# Disable code depending on optimsation level

**URL:** <https://discourse.julialang.org/t/disable-code-depending-on-optimsation-level/90589>\
**Category:** General Usage\
**Tags:** compilation, optimization\
**Created:** [November 21, 2022, 2:41pm UTC](https://discourse.julialang.org/t/disable-code-depending-on-optimsation-level/90589 "2022-11-21T14:41:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Post date:** [November 21, 2022, 2:41pm UTC](https://discourse.julialang.org/t/disable-code-depending-on-optimsation-level/90589/1 "2022-11-21T14:41:30Z")

</div>

I have input and consistency checks that I need during development but want to disable for final runs of my code. Is there a way to annotate these checks s.t. they are not included at higher optimisation levels or depending on other global settings?

For example, if these consistency checks are boundschecks I could annotate the corresponding code with `@boundscheck` and then after development start a julia process with `julia --checkbounds no` to disable the corresponding code.

Or in C/C++ I would wrap the corresponding code in a

```nohighlight
# ifdef DEBUG
// check consistency
# endif

```

and have a line `# define DEBUG` that I would comment out once I am done debugging.

Is there a similar mechanism in julia or what is the recommended way to enable some code only in debugging mode?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 21, 2022, 2:56pm UTC](https://discourse.julialang.org/t/disable-code-depending-on-optimsation-level/90589/2 "2022-11-21T14:56:18Z")

</div>

See [Debug checks without output](https://discourse.julialang.org/t/debug-checks-without-output/90458).

---

<div class="post-metadata">

**Author:** ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Post date:** [November 21, 2022, 2:57pm UTC](https://discourse.julialang.org/t/disable-code-depending-on-optimsation-level/90589/3 "2022-11-21T14:57:26Z")

</div>

You can use `@static if`, for example to disable code in some version of Julia

```julia
@static if VERSION < v"1.6"
    println("I'm old!")
    # (function definition etc. here)
end

```

I don’t often see Julia code with distinct debug modes and build modes, though. It’s less useful in a dynamic language where you don’t as often need to rerun your stuff in debug mode to figure out what is happening - you can usually use the REPL to interactively debug your problems much more effectively.
