Lilith
1
Should global consts that are Refs be UPPER_SNAKE_CASE? What do you think, and why?
It seems that there is no consensus among existing code.
The ecosystem is split:
The docs say “follow Base”
The 1.13-dev docs also say “use UPPER_SNAKE_CASE”
Base is split:
julia> filter(name -> getglobal(Base, name) isa Ref, names(Base,all=true))
16-element Vector{Symbol}:
:ACTIVE_PROJECT
:C_NULL
:ENABLE_PRECOMPILE_WARNINGS
:HOME_PROJECT
:LOADING_CACHE
:MAX_NUM_PRECOMPILE_FILES
:PKG_PRECOMPILE_HOOK
:PRECOMPILE_TRACE_COMPILE
:REFLECTION_COMPILER
:REPL_MODULE_REF
:_regex_opts_str
:_require_world_age
:_track_dependencies
:methodloc_callback
:toplevel_load
:update_stackframes_callback
Is there still a reason to use a global Ref? Why not use a typed global?
In any case, a mutable constant is not a constant in my book, so deserves lower-case IMHO.
It’s still nice when reading code to be able to instantly distinguish global state from local state…
Perhaps we need more “dimensions”, bold, italic, underlined, for more expressibility?
Agreed. I typically use UPPER_SNAKE_CASE for all globals, regardless of their const-ness.
We have far more options than most people realize:
julia> 𝐛𝐨𝐥𝐝 = 1
1
julia> 𝑖𝑡𝑎𝑙𝑖𝑐 = 2
2
julia> 𝕱𝕽𝕬𝕶𝕿𝖀𝕽 = 3
3
julia> 𝓈𝒸𝓇𝒾𝓅𝓉 = 4
4
julia> u͟n͟d͟e͟r͟l͟i͟n͟e͟d͟ = 5
5
For variables that you shouldn’t take seriously, the standard convention in Julia is to use emoji:
julia> 🤔 = missing
missing
I also use upper case snake for global variables, though I only have constant ones and very few.
But maybe switching to emojis…
And create truly cursed things like this:
🚀 = "JULIA"; 🐌 = "everything else"; ∑ = sum
📢(💬) = println("🌈✨ ", 💬, " ✨🌈")
@time ∑(x^2 for x ∈ 1:1_000_000) # 🏎️💨 FASTER THAN C (source: trust me 🤝)
📢("$(🚀) 🥇🏆 >>>>>>>>> $(🐌) 🗑️🔥 btw 😌")