mirror of
https://github.com/apple/pkl.git
synced 2026-01-13 23:23:37 +01:00
Pain Point: Deeply Nested Amends (No Flat Member Syntax) #143
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dwbrite on GitHub (Apr 12, 2024).
I'm testing Pkl as a replacement for k8s tools like Kustomize/Helm. So far it's quite nice, but one pain point is modifying deeply nested properties.
As an example, say I have a HomeAssistant pkl package with a default volume claim of 1Gi, which I'd like to bump up to 2Gi.
18 LoC for a single deeply nested amendment seems a little excessive.
One way I've found to improve this is to remove some newlines, but I don't find this ideal.
I could create late-binding variables in a new pkl module which extends
ha-appfurther, but that seems like I'd just be moving the problem down the line.Personally I'd like to see dot syntax supported for amendments. In my case, that might look something like:
Am I missing a more idiomatic solution?
@bioball commented on GitHub (Apr 12, 2024):
We'd like to add support for flat member syntax (the solution that you suggested) at some point. I definitely agree that this a pain point.
@dwbrite commented on GitHub (Apr 12, 2024):
That's great to hear, and thanks for the quick response! Feel free to change the title to something more suitable for tracking flat member syntax.
Fwiw, Pkl has been fantastic for me, and I often find myself telling people how amazing it is :)
I'm hoping I can bring it into my day job soon 🤞
@odenix commented on GitHub (Apr 12, 2024):
foo.bar.baz.qux {...}looks very similar to expressionsfoo.bar.baz.quxand(foo.bar.baz.qux) {...}, which complicates parsing and reading. I think a different syntax should at least be considered.@holzensp commented on GitHub (Apr 12, 2024):
Actually, the
(...)in object amends syntax disambiguates that entirely. A slightly trickier thing about flat member syntax is; what do you do with consecutive amends;Is that the same as
or
That has implications for what
supermeans (and for performance, but that's a shortcoming of the current implementation - albeit non-trivial). There are reasons why you're currently not allowed to amend the same property twice. Flat member syntax makes that ambiguous, because the overlap may be partial.Or... should that ambiguity should syntactically be disallowed and should this require that properties are aggregated in notation, i.e.
@bioball commented on GitHub (Apr 12, 2024):
In both of those cases,
super.fooshould have the same meaning, no? It means the parentfoovalue in the prototype chain.superby itself isn't a valid expression.An interesting problem here is what
outershould mean. It would be surprising if these two were the same:Another one is this:
It would be surprising if it expands to the below snippet, because in the below snippet, the
barwithinbaz = barreferences the middlebar, rather than the module-levelbar.@odenix commented on GitHub (Apr 12, 2024):
Distinguishing
foo.bar.baz.qux {…}fromfoo.bar.baz.quxrequires arbitrary lookahead. It’s also difficult to parse for a human, especially in the middle of a large program. The similarity with(foo.bar.baz.qux) {…}further complicates human parsing.@bioball commented on GitHub (Apr 12, 2024):
I see your point, but I'm not very convinced that this is a problem. This is unambiguous without needing lookahead:
This does require lookahead (because
bar.baz.quxis a valid expression, and expressions are valid object members):But:
Before shipping this feature, we'd definitely need to play around with this syntax in real world code.
@odenix commented on GitHub (Apr 12, 2024):
Arbitrary lookahead can cause problems with syntax highlighters and parser tools. It can also cause performance issues. It’s best avoided if possible.
https://github.com/elves/elvish/issues/664
I think that’s only the case because typed objects can’t have elements and entries. Is this limitation here to stay?
I think it’s best to avoid such assumptions when designing a feature. If the feature can be used inside objects, it will be used inside objects.
@bioball commented on GitHub (Apr 12, 2024):
No, it's because expressions are not permitted at the module level. And, this isn't likely to change.
@odenix commented on GitHub (Apr 12, 2024):
But if typed objects could have elements, it would make a lot of sense to allow expressions (elements) at the module level. This would also work great for rendering formats that support top-level arrays (JSON, etc.). Same for entries.
@odenix commented on GitHub (Apr 12, 2024):
This might be a good first (and possibly last) step. Good editor support could ease the strictness pain. Definitely worth prototyping.
Sounds like a simple expansion won't be good enough.
@bioball commented on GitHub (Apr 13, 2024):
Even if typed objects eventually allow entries and elements, I'm kind of bearish on this at the module level.
This starts to feel too much like a scripting language:
The way to render top-level arrays is to assign to
output.value, e.g.Yeah; we need to explore what the scoping rules should be. And, it might require that we start resolving variables at parse-time (within
AstBuilder.java).