Replies: 1 comment 2 replies
-
I don't have a lot to add here, I think the description, problem statement and solution are good. My second concern/request is to make sure everything is defined in v8 file and generation of documentation can be made easily with the current script and that information isn't split between multiple files. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As a casual user of maplibre-gl, I've found myself almost always skipping over the expression documentation's syntax section when trying to figure out how to properly structure expressions (i.e. when trying to figure out the syntax).
This is mainly because:
I would like to use this thread to discuss solutions to this latter point, as the former is simply an accuracy issue and is partially dependent on the latter.
TLDR: I believe the expression syntax documentation is not as useful as it should or could be, and I would like to discuss ways to resolve this through establishing patterns for documenting what is currently unclear in / missing from the syntax section.
Issues
My pain points regarding syntax clarity/informativeness largely fall under two categories.
1. Use of the
value
typeMy understanding is that
value
currently serves several uses depending on where it appears.any
), e.g. as inputs to assertion expressions like["string", value, fallback: value, fallback: value, ...]: string
in place of something like["string", any, fallback: any, fallback: any, ...]: string
["at", number, value]: value
in place of something like["at", number, array<T>]: T
["in", value, value]: boolean
in place of something like["in", T, array<T>]: boolean
and["in", string, string]: boolean
["case", value, value, ..., fallback: value]: value
in place of something like["case", boolean, any, boolean, any, ..., fallback: any]: any
I have found it very confusing to have this jumble of concerns all rolled up into a single
value
type, so I would like a solution which splits these uses into clearly distinct patterns in the syntax.2. Non-descriptive parameters
While the expression description currently pretty much always explains the type and function of the expression's parameters, the syntax often does not make it clear where each of these described parameters should be positioned.
The best (worst) examples of this are complex expressions containing multiple parameters of the same type, e.g.

match
:match
's description clearly indicates to the user that the expression accepts an 'input', 'output's, 'label's corresponding to those outputs, and a 'fallback', but the syntax only listsvalue
s — it fails to indicate which of thesevalue
s corresponds to which of the aforementioned arguments.My expectation as a user is for the syntax to help guide me in placing the arguments in the right positions for the expression to produce the result I desire, not just for it to satisfy type-checking.
I thus disagree with this decision to include only types in the syntax, and I instead agree with the sentiment behind #833 and #1065 that parameter names would help the syntax be more usable.
For example, I feel the OpenLayers expression documentation — because its syntax lists descriptive names rather than types — is much more effective at giving me a quick idea of where each argument should go in the expression:
['match', input, match1, output1, ...matchN, outputN, fallback]
.Solution
Criteria
Based on the above, I would argue that the syntax documentation should satisfy the following.
value
which are undescriptive and serve multiple functionsIdeas
I would be in favour of updating the syntax section to something like the examples below.
Syntax:
input
: any — Any expression, e.g.["get", "building_type"]
.labelI
: string literal | array<string literal> | array<number literal> — The i-th literal value or array of literal values to match the input against.outputI
: any — The expression result when the i-th label is the first label to match the input.Syntax:
item
: T — The needle to search for withinarray
.array
: array<T> — The haystack through which to search foritem
.substring
: string — The needle to search for withinstring
.string
: string — The haystack through which to search forsubstring
.any
makes sense to me as a suitable replacement forvalue
where any type can be expected (seematch
). If necessary, I could make a note in the page's 'Type system' section to describe whatany
means.T
here for generics (seein
) under the assumption that most users would be familiar with this syntax or could infer what it means. I am unaware of a better way to accomplish this.in
). This pattern could also be useful to clearly show the minimum parameters needed in a variadic expression (seematch
).match
).These are just ideas — I would love to hear feedback on whether this looks like a good solution and/or what might work better.
Apologies for the long message.
I would really appreciate any input on the topic since I'm just one data point — I'd hate to implement changes that end up not being beneficial to others.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions