# Release vs. Debug in application code

**URL:** <https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912>\
**Category:** New to Julia\
**Created:** [October 16, 2021, 8:35pm UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912 "2021-10-16T20:35:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 16, 2021, 8:35pm UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/1 "2021-10-16T20:35:30Z")

</div>

I’ve just learned about conditional compilation via [Conditional code and precompilation](https://discourse.julialang.org/t/conditional-code-and-precompilation/6301). Are there any best practices to use something like this for release vs. debug mode in library code?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 16, 2021, 11:00pm UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/2 "2021-10-16T23:00:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 17, 2021, 8:53am UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/3 "2021-10-17T08:53:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 17, 2021, 9:08am UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/4 "2021-10-17T09:08:14Z")

</div>

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:

[https://docs.julialang.org/en/v1/base/base/#Base.@assert](https://docs.julialang.org/en/v1/base/base/#Base.@assert)

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.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 17, 2021, 9:13am UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/5 "2021-10-17T09:13:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 17, 2021, 9:43am UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/6 "2021-10-17T09:43:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 17, 2021, 7:17pm UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/7 "2021-10-17T19:17:54Z")

</div>

[https://github.com/JuliaLang/julia/pull/37874](https://github.com/JuliaLang/julia/pull/37874) 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.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 17, 2021, 7:34pm UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/8 "2021-10-17T19:34:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 17, 2021, 7:59pm UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/9 "2021-10-17T19:59:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 17, 2021, 8:03pm UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/10 "2021-10-17T20:03:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 18, 2021, 7:20am UTC](https://discourse.julialang.org/t/release-vs-debug-in-application-code/69912/11 "2021-10-18T07:20:04Z")

</div>

I noticed I linked the wrong PR above. I meant to link [https://github.com/JuliaLang/julia/pull/37874](https://github.com/JuliaLang/julia/pull/37874).
