No one is stopping you from making those functions useless. It warns you that you must import from Base
to actually override them.
julia> import Base.println
julia> println(args...) = nothing
println (generic function with 3 methods)
julia> import Base.@show
julia> macro show(args...)
return :(nothing) # TODO: make this a pass thru instead of a removal
end
@show (macro with 1 method)
julia> testOutputs()
3
julia> testOutputs();
Occasionally a programmer will put an @show
in the middle of an expressions, and this kind of macro override would make it break such lines.
The better alternatives IMHO are to use a logging library like Memento.jl
or the baked in Logging of julia. They have single line functions for mass disabling logging thru their mechanisms.
https://docs.julialang.org/en/v1/stdlib/Logging/
https://docs.julialang.org/en/v1/stdlib/Logging/#Logging.disable_logging
julia> @debug "Hello World"
julia> @info "Hello World"
[ Info: Hello World
julia> @warn "Hello World"
┌ Warning: Hello World
└ @ Main REPL[10]:1
julia> @error "Hello World"
┌ Error: Hello World
└ @ Main REPL[11]:1
julia> using Logging
julia> Logging.disable_logging(Logging.Error)
LogLevel(2001)
julia> @debug "Hello World"
julia> @info "Hello World"
julia> @warn "Hello World"
julia> @error "Hello World"
https://invenia.github.io/Memento.jl/latest/
Memento.config!("emergency")
Or without any additional libraries make a global flag at the top of your file called debug_print
and swap it when needed.
julia> global debug_print = true
true
julia> function testOutputs()
debug_print && @show("Show macro still showing")
debug_print && println("Println still showing")
a = 1 + 2
end
testOutputs (generic function with 1 method)
julia> testOutputs();
"Show macro still showing" = "Show macro still showing"
Println still showing
julia> debug_print = false
false
julia> testOutputs();