-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add concept of configurability to language #41
Comments
Some questions/thoughts on this:
|
Here's what I see as the requirements:
Yes the X config model worked quite well ... and they had both a class and instance approach too. In Ballerina, module level constructs (whether they're public or not) have globally unique names: orgName/moduleName:identifier. If such construct has structure (object, service, function) then can do identifier.x.y to get to the value. For record types a similar approach could work to address the property who's value is being set (even if the type decl is inside some other construct). Anonymous types can be ignored. The programmer should indicate that the property should allow external configuration. I was thinking of a Yes validation will be important and we'll need to decide what to do when validation fails - e.g. if the an integer variable is given a config value of type string then what? I guess startup failure would be ideal (in X it was silently ignored or logged to the console IIRC). We have to decide where the config values are coming from too. For compile time values, the project's Ballerina.toml is a natural location. For runtime values we could follow something like X but I'm not thrilled with tying it to a file in a user home type thing. Maybe an environment var that gives the filename is better. That's more like the configMap stuff in K8s I think. |
One more point: We also need some values to be kept encrypted. We have a model for that too in the current config approach .. see https://ballerina.io/learn/by-example/config-api.html for an example. |
Most of this does not sound like it belongs in the language spec. I think we need to start a separate platform spec that can define this sort of thing, including TOML file, project layout etc. From a language perspective, it seems to me that we only need a modifier (as you suggest). From that perspective, the semantics are just that the value specified in the program may be overridden by something external to the program. It's a bit like |
I wonder how this should relate to |
I wondered about that too. It feels orthogonal as that's about other devs being able to see something from this module whereas config is about saying "I want to let someone give a value for this". I agree its time to start a platform spec; there's a lot of stuff that needs to be covered there including namespace management of organization names. Ref the comment about "It's a bit like external except that in that case the value is always specified externally": what I had in mind is |
Another application of this basic concept is in i18n, where a localization of the user interface (e.g. error messages) to a specific language needs to be able to substitute strings in the source with strings from the target language. |
You might want to force an outside config for a password or other security related stuff. |
For i18n we probably should look at some standard approach for resource bundles that are tied to the locale. Otherwise every program will have its own way of doing i18n of strings. |
Each programming language has its own standard way of doing this: there is no language independent standard for this as far as I am aware. If we have the configurable concept, which can handle this, why would we not use that concept for this? |
Yes same concept. However, because i18n is special and different (e.g. its not usually changed by the system admin deploying a solution), I feel we need a platform defined standard way to locate local specific resource bundles. For example, a product built in Ballerina may ship with multiple language resource files but someone may need to add another for their language. That kind of thing is different from changing the default port. Anyway lets wait for the platform level design part and see how it will play out. Maybe we don't need specialization for i18n. |
Basic idea is to declare a module-level variable/const as Things to think through:
|
There also ought eventually to be a way to specify constraints on the valid values (e.g. must be positive). This relates to #239 and #238. I think this can be handled within the framework of #238 by saying that the constraint is part of the type, and one of the language-defined points at which these constraints are checked is as part of configuration. |
Once we have this feature, we need to make the code 2 cloud stuff also work seamlessly with this. For example, a configurable item should be configurable via a Kubernetes ConfigMap. |
For Swan Lake, we are doing this in a very simplified form as follows. There is a new
The semantics of configurable are to transform the semantics of the initializer expression. At the point where the expression E would normally be evaluated, the transformed semantics are:
We allow a special value of Configured values would always a subtype of |
Add configurability as a language-level concept. The source code would be declare something configurable and then there would be a standard way at runtime to supply a value for something configurable in place of the default.
This should apply to at least:
The text was updated successfully, but these errors were encountered: