Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The case for options without values #386

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

Closed
eemeli opened this issue Jun 5, 2023 · 3 comments
Closed

The case for options without values #386

eemeli opened this issue Jun 5, 2023 · 3 comments
Labels
syntax Issues related with syntax or ABNF

Comments

@eemeli
Copy link
Collaborator

eemeli commented Jun 5, 2023

TL;DR: Supporting implicit-true unvalued options would provide better UX for developers and translators and simplify validation.

Consider a function that accepts a keyword as its primary argument, say :brand for looking up the appropriate localized form of a brand name. Right now, this is achievable in two ways:

{|foo-thing| :brand}
{:brand key=foo-thing}

While both of these kinda work, neither is particularly pleasant to use. If #364 is accepted, the first one improves a bit:

{foo-thing :brand}

However, this order makes autocompletion impossible. Let's presume that the function registry is providing a known set of valid brands that may be localised, and it's only foo-thing. Then, by the time you've entered {fog-thing, there's no way to know if this is valid or not because the function hasn't been identified yet. To get there, you need to type all of {fog-thing :brand}, and then go back and fix your mistake.

Using the key= approach is a little bit better in this regard, but really those four characters are rather superfluous, and as with the positional argument, the value might be a variable. This means that it could be valid to write {:brand key=$foo}, and we wouldn't know until formatting time which brand we're localising. That's pretty powerful (much like dynamic message references, actually), but in many cases perhaps too powerful.

Instead, I think we ought to support unvalued options, so that this becomes possible:

{:brand foo-thing}

This has three benefits over the current alternatives:

  1. Autocompletion can "just work", so writing MF2 feels more natural.
  2. Option names cannot be variable, so we can validate the expression without consideration of runtime values.
  3. Option basket validation becomes easier, because it depends on the presence of specific options, rather than the value assigned to them.

If we don't support unvalued options, we probably ought to introduce a way that the function registry can specify that a positional argument or an option value cannot be set by a variable. Though tbh that would probably make sense independently of this.

@stasm
Copy link
Collaborator

stasm commented Jun 5, 2023

{:brand foo-thing}

Knowing what this use-case is supposed to do, I'd say foo-thing is a positional argument rather than a boolean option name. Consequently, I wouldn't expect the registry to list all possible different message ids as potential options of the :brand function.

(I tend to think that :brand id=foo-thing is rather nice and self-documenting.)

An example of a boolean option that I could see a use-case for is something like {$item :noun capitalized}. However, I also think that {$item :noun lettercase=capitalized} is equally good, if not better: it's consistent with other options and likely easier to work with both as a translator (easier to autocomplet) and the implementer of the :noun function (all option values can be assumed to be strings).

@aphillips
Copy link
Member

Interesting.

Some initial observations (don't read this as rejection, just being the devil's advocate):

That's pretty powerful (much like dynamic message references, actually), but in many cases perhaps too powerful.

I don't buy this argument. It's super common to have the value be in a variable passed at runtime--otherwise you'd just hardcode the brand name into the message.

Just to be clear, an "unvalued option" means that foo-thing is a key in the argument map. Note that "unvalued options" are sometimes called "flags" 😀

Are you thinking about the case where the unvalued option is not a closed enumerated set? Autocompletion, for example, only works when the set is closed ("hardcoded in the function registry"). Many cases like this have value sets that evolve over time (the "product name" API I've mentioned in this group previously purposefully didn't bind to a specific set of product IDs... because we built new ones all the time)

Some values will require quoted literals. So {|foo thing| :brand} is still a thing 😸and so is {:brand |foo thing|}. Note that the latter breaks the namespace contract of key (which is okay if the arguments are passed in a map)

@aphillips
Copy link
Member

This was rejected in the 2024-01-08 call. In 2.0, options require values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
syntax Issues related with syntax or ABNF
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants