Skip to content
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

Specify optional and named parameters #325

Merged
merged 9 commits into from
Oct 8, 2020
Merged

Conversation

domenic
Copy link
Member

@domenic domenic commented Aug 17, 2020

Closes #320.


Preview | Diff

@domenic domenic force-pushed the named-optional-params branch from 9124f24 to 83e5008 Compare August 17, 2020 21:25
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks for formalizing this!

I'm not entirely convinced we want the last paragraph however. Making that tradeoff seems extremely nuanced and I'd rather folks either use a struct or not name the parameters.

infra.bs Outdated Show resolved Hide resolved
"<code>form submission</code>".

<li><a href=#example-navigate-algo-positional>Navigate</a> to <var ignore>resource</var> with
"<code>form submission</code>" and true.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we should call out positional booleans as bad practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really want to do that I guess that would further argue for special casing booleans in some ways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I dunno, it's OK-ish especially since it's all hypertext, but I agree generally it's not going to be a good time, and you probably want your booleans to be named.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems based on the discussion we should change this too, right? To only have examples with recommended practice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I'm unsure because it's part of the "narrative flow" of the section: it shows the algorithm evolving from unclear and inflexible optional positional arguments, to clear and flexible optional named arguments.

We could instead specifically explain that not only is this non-ideal because of the ordering restrictions, but also because of the presence of non-named boolean parameters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds good to me. I suspect that would work for @jyasskin too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks. Note that this example-of-things-we-don't-want-people-to-do winds up looking the same as all the other examples-of-things-to-do. Vanilla bikeshed supports a heading="Bad Example" attribute to make it a little clearer, but that attribute doesn't work with the WHATWG style sheet's .example::before { content: 'Example'; } rule.

infra.bs Outdated
Comment on lines 385 to 388
<p>Non-optional named parameters may also be used, using the same convention of marking them up as
both variables and definitions, and linking to them from call sites. However, one should default to
making non-optional parameters positional, for simplicity and uniformity. Non-optional named
parameters should only be used when they significantly improve clarity, and even then it might be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think Call foo with 3 and Call foo with "navigate" are not much better than Call foo with false, and Infra should encourage people to name those non-optional parameters. Perhaps:

Suggested change
<p>Non-optional named parameters may also be used, using the same convention of marking them up as
both variables and definitions, and linking to them from call sites. However, one should default to
making non-optional parameters positional, for simplicity and uniformity. Non-optional named
parameters should only be used when they significantly improve clarity, and even then it might be
<p>Non-optional parameters may also be named, using the same convention of marking them up as
both variables and definitions, and linking to them from call sites. Do this when it improves
clarity at call sites. It is also

"<code>form submission</code>".

<li><a href=#example-navigate-algo-positional>Navigate</a> to <var ignore>resource</var> with
"<code>form submission</code>" and true.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks. Note that this example-of-things-we-don't-want-people-to-do winds up looking the same as all the other examples-of-things-to-do. Vanilla bikeshed supports a heading="Bad Example" attribute to make it a little clearer, but that attribute doesn't work with the WHATWG style sheet's .example::before { content: 'Example'; } rule.

@domenic
Copy link
Member Author

domenic commented Oct 1, 2020

So, this has been sitting for a while. I'd like to get it landed. Outstanding feedback:

  • @jyasskin's preference toward more named parameters, or at least against the current PR's avoidance of them, expressed in comments immediately above. I'm on the fence here. I like the idea of Infra giving guidance, but since this seems controversial, maybe Infra should be more neutral, and leave this up to editor preference.

  • @jakearchibald's feedback in Named arguments and especially named optional arguments #320 (comment) that we shouldn't use <var> at call sites. Although I recognize the logic of his position, it feels a bit icky to have camelCased things that aren't <var>, and to have the typography at the call site mismatch the definition site. So I'm weakly for the PR as-is.

@annevk, any thoughts? And if anyone wants to chime with their perspective on the above, feel free to do so.

@annevk
Copy link
Member

annevk commented Oct 5, 2020

I think encouraging naming for optional arguments is reasonable, but I'm okay with not endorsing anything for now, especially as there is no tooling support either.

We could use <i> at the call site instead of <var>.

@jakearchibald
Copy link
Contributor

With <var> you have to work around it not-really-being-a-var with <var ignore>. With <i> you don't need to work around it, so it gets my vote.

@domenic domenic force-pushed the named-optional-params branch from 979c69d to 5cf09a1 Compare October 7, 2020 17:12
@domenic
Copy link
Member Author

domenic commented Oct 7, 2020

Alright, this might be ready to go then!

Copy link
Member

@jyasskin jyasskin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

infra.bs Outdated Show resolved Hide resolved
infra.bs Outdated Show resolved Hide resolved
domenic and others added 2 commits October 7, 2020 14:27
Co-authored-by: Jeffrey Yasskin <jyasskin@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Named arguments and especially named optional arguments
4 participants