Release vs. Debug in application code

I’ve just learned about conditional compilation via Conditional code and precompilation. Are there any best practices to use something like this for release vs. debug mode in library code?

just use @debug macro, and then if you don’t have anything set, it will be release

1 Like

Do packages use @debug to do thinks like invariant checking?

No. @debug is macro for generating logging messages from the Logging stdlib.

Julia per se has no concept of debug vs. release, as such there are no debug-only asserts that are removed in compilation. This may be a future feature, if/when static compilation becomes a thing, but no guarantees so far.

Also, @assert has no documentation about when it is removed, if at all:

I think most packages that do rigorous testing rely mostly unit testing as well as some form of defensive programming for checking invariants. Another option would be to employ property based testing, to fuzz inputs.


Should I mark this as solution although it is not a solution I like very much?

If it answers your original question, sure.

It should be noted that julia by design is a dynamic language and “precompilation” is not the same as full static compilation to CPU instructions. It’s a lowering cache, IIRC to the parsed & expanded julia code. Static compilation to e.g. a shared object or executable binary artifact is a work in progress, the current “state of the art” so to speak is PackageaCompiler.jl. You’re not alone with these wishes, rest assured.

RFC: implement proper debug mode for packages (with support for re-precompilation) by KristofferC · Pull Request #37874 · JuliaLang/julia · GitHub has an implementation of a debug mode. There was some worries about it though, like people thought they were going to have to run tests both in debug mode and without etc.


Hi Kristoffer,

I strongly agree there should be a mechanism to trigger whatever expensive self testing capabilities in library code. One thing I’d like to switch on and off for example would be @inbounds.

Anectodal evidence: I experienced my first system crash for a long time today during testing some Distributed stuff getting an ACCVIO with accompanying ‘please report bug’ due to my programming mistake and @inbounds before (and no, luckily it was not reproducible, so I don’t know if it was a hardware or OS hickup, but I didn’t try to hard;)

And interestingly enough: in a different thread we happily discuss about integer overflow.

You can disable inbounds already with --check-bounds=yes

1 Like

So they (= language implementors) should give us a flag for debug testing?

I noticed I linked the wrong PR above. I meant to link RFC: implement proper debug mode for packages (with support for re-precompilation) by KristofferC · Pull Request #37874 · JuliaLang/julia · GitHub.