# Conditionally define modules?

**URL:** <https://discourse.julialang.org/t/conditionally-define-modules/143185>\
**Category:** General Usage\
**Created:** [November 25, 2026, 6:48am UTC](https://discourse.julialang.org/t/conditionally-define-modules/143185 "2026-11-25T06:48:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zchenytt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zchenytt/32/223795_2.png) [@zchenytt](https://discourse.julialang.org/u/zchenytt)\
**Post date:** [November 25, 2026, 6:48am UTC](https://discourse.julialang.org/t/conditionally-define-modules/143185/1 "2026-11-25T06:48:11Z")

</div>

I find this way of organizing my computing workflow interesting.

```julia-auto
julia> CONFIG = (; S = nothing); # define this in the main module

julia> CONFIG === Main.CONFIG
true

julia> module My1 # my custom module 1
           import ..CONFIG
           const B = isnothing(CONFIG.S)
       end;

julia> module My2 # my custom module 2 that should depend on `My1`
           import ..My1
           function f(x)
               if My1.B
                   print("code_block_1")
               else
                   print("code_block_2")
               end
           end
       end;

julia> My2.f(0)
code_block_1

```

I wonder if the `code_block_2` could be effectively removed during its compile time.

I also want to know if this is already a good design. (Now it reads pretty clear). (Note that I don’t aim to develop a “sourceless” package, e.g. to provide a function that takes all the necessary input data from the user).
