# Switch off chunks of code

**URL:** <https://discourse.julialang.org/t/switch-off-chunks-of-code/62247>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [June 2, 2021, 4:30am UTC](https://discourse.julialang.org/t/switch-off-chunks-of-code/62247 "2021-06-02T04:30:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adriel](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adriel](https://discourse.julialang.org/u/Adriel)\
**Post date:** [June 2, 2021, 4:30am UTC](https://discourse.julialang.org/t/switch-off-chunks-of-code/62247/1 "2021-06-02T04:30:26Z")

</div>

I’m wondering if there’s a way to completely remove sections of debug/analytics code via some switch, similar to `#define` in C. Currently I’m just doing this.

```julia
function f(x, analyse=false)
    # compute output
    if analyse
        # compute rarely-needed expensive statistics
    end
end

```

This is OK, but it would be nice to tell the compiler to just ignore this code when compiling for production. I believe the answer is metaprogramming, which can go deeper than I’m willing to dive, but I suspect the solution here is relatively simple.

I found a couple of related threads on stack overflow etc., but nothing that quite matches.

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [June 2, 2021, 4:36am UTC](https://discourse.julialang.org/t/switch-off-chunks-of-code/62247/2 "2021-06-02T04:36:28Z")

</div>

Would @debug work for your use case? [Logging · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Logging/)

---

<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:** [June 2, 2021, 5:02am UTC](https://discourse.julialang.org/t/switch-off-chunks-of-code/62247/3 "2021-06-02T05:02:23Z")

</div>

FYI, `@debug` doesn’t seem to construct the output if the enabled loglevel is higher than the one specified by the macro (Debug in this case). So it should work properly.

---

<div class="post-metadata">

**Author:** ![Adriel](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adriel](https://discourse.julialang.org/u/Adriel)\
**Post date:** [June 2, 2021, 5:02am UTC](https://discourse.julialang.org/t/switch-off-chunks-of-code/62247/4 "2021-06-02T05:02:33Z")

</div>

Yes it would!. Thanks.
