|
|
|
|
|
by Nihilartikel
2150 days ago
|
|
It takes the will and discipline to use it, but what Clojure Spec (and other schemata libs) offer is, in a lot of ways, more powerful and flexible than traditional type systems.
A spec can be thought of more as a contract with the data, one with enough detail that it can be used to auto-generate conformant example data even.
If, for instance, you have a function, that needs to work on either, integers, or numeric strings, and textual fractions like '1/5'. Enforcing this constraint on input, and getting informative exceptions on bad data is easy with a spec, and the function code does not need to contain all of the noise to validate or coerce data.
Sure, you don't see the problem at compile time, but if you can auto-generate test data, the tests that you should already have become easier to write. |
|