Currently the default value for clojure.core/*assert*
is true
.
This has some implications for library creators and consumers.
As a library creator you can't just add asserts everywhere to help you on dev/test because it will make most users pay the performance price in production, since they will be running with *asserts*
enable.
As a library consumer, since you don't know what libraries are using asserts, you have to always remember to disable them just in case.
This is worsen by the fact that is not easy to disable them globally in Clojure, since assert
is a macro that checks *assert*
, the value of the var needs to be set before loading any namespace.
On the contrary java makes all assertions disable by default, so library creators don't have to think about this, and the consumers can explicitly enable them at dev time by providing java -ea
(enable assertions)
Since I guess changing the default value of *assert*
could be problematic because of backwards compatibility, it would maybe be possible to add a debug-assert
like is the case of Rust, which will not be on by default.
As I see it, the important part is having a simple invariant checking instruction that we know is not going to impact performance by default, so hardening our code base for test and dev is not coupled to production performance in the default case.
Two other options are better default values for assert, one is false
and the other is the value of java.lang.Class desiredAssertionStatus()
which seams to return true/false depending on the -ea
flag being provided or not, which will be also false
by default., but since most Clojure users already rely on assert being true by default this are maybe not an option.