What is a good design for a settable global with a known type?

jakobjpeters
Sat, 26 Oct 2024 02:13:52 +0000
Performance

In a package, I have a const s = "" that is used in a couple of functions. One of these functions doesn’t have a way for a user to specify a different string to use instead. What is a good way to make the value settable?

a::String = ""
set_a(s) = global a = s

const b = Ref("")
set_b(s) = b[] = s

# The real variable is luckily an actual string
ENV["c"] = ""
set_c(s) = ENV["c"] = s

5 posts - 4 participants