snu-quiqcl / qiwis

QuIqcl Widget Integration Software
MIT License
5 stars 2 forks source link

Global constant namespace #185

Closed kangz12345 closed 1 year ago

kangz12345 commented 1 year ago

Feature you want to implement

To provide a global constant (read-only) namespace which can be accessed by any apps in a qiwis system. For example, artiq-proxy server host ip and port information can be stored in it. This will be initialized by the "setup.json" file.

How the feature is implemented

When loading the set-up file, the global constant namespace is initialized by the contents in the file. However, sharing a mutable object among the apps is against our philosophy. Therefore, the namespace must be immutable, i.e., read-only. namedtuple seems a nice candidate for this..

Additional context

Suggested by: @BECATRUE

BECATRUE commented 1 year ago

I also think that namedtuple is the best candidate!

However, a mutable element of namedtuple is still mutable. Doesn't this matter?

kangz12345 commented 1 year ago

However, a mutable element of namedtuple is still mutable. Doesn't this matter?

That is correct! However, we know that all the values are decoded from a JSON string, so the only mutable types are list and dict (see also: json module).

Then we can convert lists to tuples, and dicts to types.MappingProxyTypes.

BECATRUE commented 1 year ago

Oh, thanks for the details!