4 ms·
I think there are a few benefits. First and foremost, schemas are simple, minimal, easy to read and write, and gracefully extend Clojure's existing type hints.
by w01fe 13y ago
I think there are a few benefits.
First and foremost, schemas are simple, minimal, easy to read and write, and gracefully extend Clojure's existing type hints. This means that (in my biased opinion) they are significantly better for documentation, which was the primary motivation for developing them.
Second, schemas are data, so it's easy to do more with them beyond documentation. Runtime data validation is one such use, but we can also easily do things like generate core.typed annotations, generate model classes for clients, generate test data, and so on.
- ambrosebs 13y agoAuthor of core.typed here. I will challenge that schemas are "significantly" better for documentation than core.typed types. With unions, intersections, heterogeneous maps, parameterised classes, recursive types we can be very expressive. Here's some examples of the syntax for types: https://github.com/clojure/core.typed/wiki/Types https://github.com/clojure/core.typed/wiki/Types And some declarative types in action: https://github.com/frenchy64/core.typed-example/blob/master/src/fire/simulate.clj#L42 https://github.com/frenchy64/core.typed-example/blob/master/... I think core.typed is restrictive enough to allow annotations like the one above, while being opinionated enough to guide the programmer to write clear, comprehensible types.
- w01fe 13y agoSorry, that didn't come across the way I wanted -- it certainly wasn't meant as a dig on the expressiveness or power of core.typed, which is a project I'm really excited about. The main driver for Schema was to make annotating function inputs and outputs as simple and readable as possible. Personally, I find annotations directly on the function arguments easier to parse than separate function type declarations, but I suppose that's a matter of preference.
- ambrosebs 13y agoNo problem, just was eager to clarify :) FWIW there are macros like fn> that allow you to write (fn> :- Number [a :- Symbol] 1), but you lose the ability to write ordered function types with multiple cases, so I don't use it very much.