4 ms·
> Typed global variables will be great What purpose do you see for typed global variables? I'm sure they'll be useful for interfacing with external ABIs, OS in
by nsajko 4y ago
> Typed global variables will be great
What purpose do you see for typed global variables? I'm sure they'll be useful for interfacing with external ABIs, OS interfaces, or hardware; but I'm not sure the added complexity will be worth it in the end, as these use cases seem rare. For one, it'll now be more difficult for newbies to understand they shouldn't use global variables in packages unless absolutely necessary.
- eigenspace 4y agoI see typed global variables as replacement for writing const x = Ref{Int}(1) and then mutating it as `x[] += 1`. With the type annotated globals, we'll be able to simply write x::Int = 1 and rebind it as `x += 1`. Besides the syntactic advantage, this way is threadsafe by default whereas mutating a constant global `Ref` is not threadsafe.
- nsajko 4y ago> this way is threadsafe by default No? Concurrent updates of integers can be accomplished with atomics: https://docs.julialang.org/en/v1/manual/multi-threading/#Atomic-Operations https://docs.julialang.org/en/v1/manual/multi-threading/#Ato...