Two potential advantages are lower RAM usage, and very fast comparison because strcmp
becomes a pointer comparison rather than character-by-character. The trade-off is that every string construction then requires a hash table look up.
The computer science name for this technique is string interning. Julia’s Symbol
type is interned like that, and I believe I’ve seen posts about (ab)using it for general string interning – but I’m not sure if such a use-case is intended .
See also: [ANN] InternedStrings.jl: Allocate strings once and reuse them