<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged assert</title>
<link>https://ask.clojure.org/index.php/tag/assert</link>
<description></description>
<item>
<title>Add `debug-assert` as a separate, off-by-default operation for expensive dev/test-only assertions</title>
<link>https://ask.clojure.org/index.php/13666/debug-assert-separate-default-operation-expensive-assertions</link>
<description>&lt;p&gt;Currently the default value for &lt;code&gt;clojure.core/*assert*&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This has some implications for library creators and consumers.&lt;/p&gt;
&lt;p&gt;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 &lt;code&gt;*asserts*&lt;/code&gt; enable.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;This is worsen by the fact that is not easy to disable  them globally in Clojure, since &lt;code&gt;assert&lt;/code&gt; is a macro that checks &lt;code&gt;*assert*&lt;/code&gt;, the value of the var needs to be set before loading any namespace.&lt;/p&gt;
&lt;p&gt;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 &lt;code&gt;java -ea&lt;/code&gt; (enable assertions)&lt;/p&gt;
&lt;p&gt;Since I guess changing the default value of &lt;code&gt;*assert*&lt;/code&gt; could be problematic because of backwards compatibility, it would maybe be possible to add a &lt;code&gt;debug-assert&lt;/code&gt; like is the case of Rust, which will not be on by default.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Two other options  are better default values for &lt;em&gt;assert&lt;/em&gt;, one is &lt;code&gt;false&lt;/code&gt; and the other is the value of &lt;code&gt;java.lang.Class desiredAssertionStatus()&lt;/code&gt; which seams to return true/false depending on the &lt;code&gt;-ea&lt;/code&gt; flag being provided or not, which will be also &lt;code&gt;false&lt;/code&gt; by default., but since most Clojure users already rely on &lt;em&gt;assert&lt;/em&gt; being true by default this are maybe not an option. &lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13666/debug-assert-separate-default-operation-expensive-assertions</guid>
<pubDate>Tue, 06 Feb 2024 17:42:43 +0000</pubDate>
</item>
<item>
<title>Would be awesome have a system property to set the value of *assert* (clojure)</title>
<link>https://ask.clojure.org/index.php/9071/would-awesome-have-system-property-set-value-assert-clojure</link>
<description>&lt;p&gt;In clojurescript we have &lt;code&gt;:elide-asserts&lt;/code&gt; option that allows at compile time specify if i want to enable asserts or disable. Clojure has similar mechanism with the &lt;code&gt;*assert*&lt;/code&gt; var but misses the way to set it before execute/evaluate any other code.&lt;/p&gt;
&lt;p&gt;I know, with tool.deps, you have the &lt;code&gt;-e &quot;(set! *assert* false)&quot;&lt;/code&gt;  but this only works if you are using tool.deps to start your application (pretty common on development but not so common on production). &lt;/p&gt;
&lt;p&gt;Another precedent is the &lt;code&gt;clojure.spec.check-asserts&lt;/code&gt; system property, that only works for clojure.spec. &lt;/p&gt;
&lt;p&gt;Would be awesome to have a similar system property to the &lt;code&gt;clojure.spec.check-asserts&lt;/code&gt; for specify the value for &lt;code&gt;*assert*&lt;/code&gt; var.&lt;/p&gt;
&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2554&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2554&lt;/a&gt;&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9071/would-awesome-have-system-property-set-value-assert-clojure</guid>
<pubDate>Fri, 31 Jan 2020 16:58:21 +0000</pubDate>
</item>
</channel>
</rss>