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

The '?' and '!' syntax in algorithms is very poorly chosen #568

Open
bzbarsky opened this Issue May 13, 2016 · 27 comments

Comments

Projects
None yet
@bzbarsky

bzbarsky commented May 13, 2016

There are several problems:

  1. The choice to optimize for brevity at the expense of readability means the sigils are actually quite easy to miss. Especially '!', which is quite thin.
  2. '!' has existing meanings as "not" that confuse people (e.g. when people see ! IsCallable(obj) in an algorithm they think that it means "obj is not callable".

Especially as people try to use these sigils in other specifications, with less-expert audiences than ecma262, this is causing real problems. I see the value in using a single algorithm-definition language in ecma262 and other specifications that define things in terms of EcmaScript objects, but if we want to do that we should seriously consider a more understandable syntax.

As a specific suggestion, '!' could be replaced with "unbox" or something along those lines. It would retain the clarity of extracting a value from the completion record, but make it even more clear that something nontrivial is going on, and for people who have never seen the syntax before make them stop and think about what "unbox" actually means instead of assuming that there's just a stray character in the spec draft, which is what they do now when they see the '?' and '!'.

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson May 13, 2016

Member

"unbox" doesn't say what "!" does which is both an unboxing and an assertion that the completion record is never an abrupt completion. The latter is really the most important part.

I'm open to changing (and agree with point 2 above) but I'd need to see a good alternative. We did discuss alternatives for some time so I don't anticipate this will be an easy task :)

Member

bterlson commented May 13, 2016

"unbox" doesn't say what "!" does which is both an unboxing and an assertion that the completion record is never an abrupt completion. The latter is really the most important part.

I'm open to changing (and agree with point 2 above) but I'd need to see a good alternative. We did discuss alternatives for some time so I don't anticipate this will be an easy task :)

@bzbarsky

This comment has been minimized.

Show comment
Hide comment
@bzbarsky

bzbarsky May 13, 2016

I'm not tied to "unbox", though it's common for "unbox" operations to assert that the unboxing is ok....

Is the existing discussion archived somewhere, in full or summary form? What alternatives were considered?

bzbarsky commented May 13, 2016

I'm not tied to "unbox", though it's common for "unbox" operations to assert that the unboxing is ok....

Is the existing discussion archived somewhere, in full or summary form? What alternatives were considered?

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson May 13, 2016

Member

#105 and #129 have some discussion. Not sure where the bulk of the syntax bike shedding happened, although much of it was IRC/elsewhere.

Member

bterlson commented May 13, 2016

#105 and #129 have some discussion. Not sure where the bulk of the syntax bike shedding happened, although much of it was IRC/elsewhere.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache May 13, 2016

Contributor

I have to make some effort in order to not read "!" as "not"...

The best I'm currently thinking of are "unbox-or-throw" and "nothrow-unbox".

Contributor

claudepache commented May 13, 2016

I have to make some effort in order to not read "!" as "not"...

The best I'm currently thinking of are "unbox-or-throw" and "nothrow-unbox".

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb May 13, 2016

Member

? ᕕ( ᐛ )ᕗ

Member

ljharb commented May 13, 2016

? ᕕ( ᐛ )ᕗ

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb May 13, 2016

Member

! -> 👌
? -> 🤔

Member

allenwb commented May 13, 2016

! -> 👌
? -> 🤔

@bzbarsky

This comment has been minimized.

Show comment
Hide comment
@bzbarsky

bzbarsky May 13, 2016

I recomend using something people might actually have the fonts for.... ;)

bzbarsky commented May 13, 2016

I recomend using something people might actually have the fonts for.... ;)

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson May 13, 2016

Member

I am not against using Unicode for this in case folks are joking. It's not hard to set up your editor to make things easy to author and we have precedent (eg. « »).

I think ⏎ is reasonable for return-if-abrupt but I can't think of a good alternative for !.

Member

bterlson commented May 13, 2016

I am not against using Unicode for this in case folks are joking. It's not hard to set up your editor to make things easy to author and we have precedent (eg. « »).

I think ⏎ is reasonable for return-if-abrupt but I can't think of a good alternative for !.

@bzbarsky

This comment has been minimized.

Show comment
Hide comment
@bzbarsky

bzbarsky May 14, 2016

#105 and #129 have some discussion.

Thanks. None of the discussion there really considers non-single-char alternatives, looks like, or indeed any chars other than '!' and '?'...

There are suggestions in those issues to auto-linkify, though, which I think would have been a good idea no matter what: "read the algorithm conventions" is hard enough inside ecma262, given that they're not very prominent, but people are now trying to use this syntax in other specs, without ever really making it clear that they're using the ecma262 conventions ... and expecting people to guess that while in the middle of spec A (which is where they got dumped when they followed a link for "spec for X") they really need to go read some mildly-hidden preface matter from spec B to understand the notation is pretty annoying. ;)

bzbarsky commented May 14, 2016

#105 and #129 have some discussion.

Thanks. None of the discussion there really considers non-single-char alternatives, looks like, or indeed any chars other than '!' and '?'...

There are suggestions in those issues to auto-linkify, though, which I think would have been a good idea no matter what: "read the algorithm conventions" is hard enough inside ecma262, given that they're not very prominent, but people are now trying to use this syntax in other specs, without ever really making it clear that they're using the ecma262 conventions ... and expecting people to guess that while in the middle of spec A (which is where they got dumped when they followed a link for "spec for X") they really need to go read some mildly-hidden preface matter from spec B to understand the notation is pretty annoying. ;)

@rossberg

This comment has been minimized.

Show comment
Hide comment
@rossberg

rossberg May 14, 2016

Member

On 13 May 2016 at 23:49, Claude Pache notifications@github.com wrote:

I have to make some effort in order to not read "!" as "not"...

It's C's fault to make such a terrible and abusive choice for its "not"
operator... :)

Member

rossberg commented May 14, 2016

On 13 May 2016 at 23:49, Claude Pache notifications@github.com wrote:

I have to make some effort in order to not read "!" as "not"...

It's C's fault to make such a terrible and abusive choice for its "not"
operator... :)

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache May 17, 2016

Contributor

Here’s the result of my cogitation:

?unbox check (to be applied from right to left);
!unbox. The absence of check is an implicit assertion.

One could replace unbox and/or check, by some symbol; however we should make sure that it remains sufficiently clear for the occasional reader, especially in the few places where unboxing or returning-if-abrupt is not performed.

Contributor

claudepache commented May 17, 2016

Here’s the result of my cogitation:

?unbox check (to be applied from right to left);
!unbox. The absence of check is an implicit assertion.

One could replace unbox and/or check, by some symbol; however we should make sure that it remains sufficiently clear for the occasional reader, especially in the few places where unboxing or returning-if-abrupt is not performed.

@michaelficarra

This comment has been minimized.

Show comment
Hide comment
@michaelficarra

michaelficarra May 17, 2016

Member

If we're going to stick with symbolism, I'm partial to these square-based operators:

  • ⊡ 'SQUARED DOT OPERATOR' (U+22A1)
  • ⧆ 'SQUARED ASTERISK' (U+29C6)
  • ⧄ 'SQUARED RISING DIAGONAL SLASH' (U+29C4)
  • ⧇ 'SQUARED SMALL CIRCLE' (U+29C7)
  • ⧈ 'SQUARED SQUARE' (U+29C8)
  • ◳ 'WHITE SQUARE WITH UPPER RIGHT QUADRANT' (U+25F3)
  • ▣ 'WHITE SQUARE CONTAINING BLACK SMALL SQUARE' (U+25A3)
  • ☒ 'BALLOT BOX WITH X' (U+2612)
  • ☑ 'BALLOT BOX WITH CHECK' (U+2611)

There's also a large selection of circle-based operators:

  • ⊕ 'CIRCLED PLUS' (U+2295)
  • ⊗ 'CIRCLED TIMES' (U+2297)
  • ⊙ 'CIRCLED DOT OPERATOR' (U+2299)
  • ⊛ 'CIRCLED ASTERISK OPERATOR' (U+229B)
  • ⊜ 'CIRCLED EQUALS' (U+229C)
  • ⎊ 'CIRCLED TRIANGLE DOWN' (U+238A)
  • ⦹ 'CIRCLED PERPENDICULAR' (U+29B9)
  • ⦼ 'CIRCLED ANTICLOCKWISE-ROTATED DIVISION SIGN' (U+29BC)
  • ⦾ 'CIRCLED WHITE BULLET' (U+29BE)
  • ⦿ 'CIRCLED BULLET' (U+29BF)
  • ⧁ 'CIRCLED GREATER-THAN' (U+29C1)
Member

michaelficarra commented May 17, 2016

If we're going to stick with symbolism, I'm partial to these square-based operators:

  • ⊡ 'SQUARED DOT OPERATOR' (U+22A1)
  • ⧆ 'SQUARED ASTERISK' (U+29C6)
  • ⧄ 'SQUARED RISING DIAGONAL SLASH' (U+29C4)
  • ⧇ 'SQUARED SMALL CIRCLE' (U+29C7)
  • ⧈ 'SQUARED SQUARE' (U+29C8)
  • ◳ 'WHITE SQUARE WITH UPPER RIGHT QUADRANT' (U+25F3)
  • ▣ 'WHITE SQUARE CONTAINING BLACK SMALL SQUARE' (U+25A3)
  • ☒ 'BALLOT BOX WITH X' (U+2612)
  • ☑ 'BALLOT BOX WITH CHECK' (U+2611)

There's also a large selection of circle-based operators:

  • ⊕ 'CIRCLED PLUS' (U+2295)
  • ⊗ 'CIRCLED TIMES' (U+2297)
  • ⊙ 'CIRCLED DOT OPERATOR' (U+2299)
  • ⊛ 'CIRCLED ASTERISK OPERATOR' (U+229B)
  • ⊜ 'CIRCLED EQUALS' (U+229C)
  • ⎊ 'CIRCLED TRIANGLE DOWN' (U+238A)
  • ⦹ 'CIRCLED PERPENDICULAR' (U+29B9)
  • ⦼ 'CIRCLED ANTICLOCKWISE-ROTATED DIVISION SIGN' (U+29BC)
  • ⦾ 'CIRCLED WHITE BULLET' (U+29BE)
  • ⦿ 'CIRCLED BULLET' (U+29BF)
  • ⧁ 'CIRCLED GREATER-THAN' (U+29C1)
@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson May 17, 2016

Member

@michaelficarra I was also playing around with the square operators. Ballot box with x (with color: black which fixes the default red rendering on Windows at least) speaks to me as an unboxing operator, but I can't figure out a good way to differentiate an unbox return-if-abrupt from an unbox never abrupt. @michaelficarra what operators do you like for ?/! today?

I like unbox as a keyword too, as @claudepache suggests. check doesn't speak to me though. Also not sure about right-to-left evaluation order. What about unbox-normal and unbox-return or unbox-ria?

Member

bterlson commented May 17, 2016

@michaelficarra I was also playing around with the square operators. Ballot box with x (with color: black which fixes the default red rendering on Windows at least) speaks to me as an unboxing operator, but I can't figure out a good way to differentiate an unbox return-if-abrupt from an unbox never abrupt. @michaelficarra what operators do you like for ?/! today?

I like unbox as a keyword too, as @claudepache suggests. check doesn't speak to me though. Also not sure about right-to-left evaluation order. What about unbox-normal and unbox-return or unbox-ria?

@annevk

This comment has been minimized.

Show comment
Hide comment
@annevk

annevk May 17, 2016

Contributor

If you go as far as having Unbox and Check, then perhaps they should simply be abstract operations?

Contributor

annevk commented May 17, 2016

If you go as far as having Unbox and Check, then perhaps they should simply be abstract operations?

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic May 17, 2016

Member

That would kind of break the idea that all abstract ops return completion records. They're probably better as syntactically "special" macros.

FWIW I like the current punctuators although the ! vs. negation confusion is sometimes annoying.

Member

domenic commented May 17, 2016

That would kind of break the idea that all abstract ops return completion records. They're probably better as syntactically "special" macros.

FWIW I like the current punctuators although the ! vs. negation confusion is sometimes annoying.

@leobalter

This comment has been minimized.

Show comment
Hide comment
@leobalter

leobalter May 17, 2016

Member

I'm not super exited with unbox but IMHO it is better than unicode special characters as I don't know how they are read on any accessibility helper. I'm afraid they will end translated as "SQUARED DOT OPERATOR", in the middle of a sentence this is way more extra information than just "question mark", etc.

That would kind of break the idea that all abstract ops return completion records. They're probably better as syntactically "special" macros.

+1

Member

leobalter commented May 17, 2016

I'm not super exited with unbox but IMHO it is better than unicode special characters as I don't know how they are read on any accessibility helper. I'm afraid they will end translated as "SQUARED DOT OPERATOR", in the middle of a sentence this is way more extra information than just "question mark", etc.

That would kind of break the idea that all abstract ops return completion records. They're probably better as syntactically "special" macros.

+1

@annevk

This comment has been minimized.

Show comment
Hide comment
@annevk

annevk May 17, 2016

Contributor

That would kind of break the idea that all abstract ops return completion records.

That they don't all return such records explicitly is something I find very confusing. Also, e.g., IsCallable does not seem to get unboxed and is assumed to return a primitive by all its callers. So I don't think we have much consistency there one way or another.

Contributor

annevk commented May 17, 2016

That would kind of break the idea that all abstract ops return completion records.

That they don't all return such records explicitly is something I find very confusing. Also, e.g., IsCallable does not seem to get unboxed and is assumed to return a primitive by all its callers. So I don't think we have much consistency there one way or another.

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson May 17, 2016

Member

FWIW I like the current punctuators although the ! vs. negation confusion is sometimes annoying.

I'm in the same boat, but if people are confused, it should be fixed.

I'm afraid they will end translated as "SQUARED DOT OPERATOR", in the middle of a sentence this is way more extra information than just "question mark", etc

To be fair, screen readers don't read the current punctuators at all (and in general the spec is miserable to use with a screen reader). A lot of work needs to be done to make this better, and I doubt it matters what sigil we use as in any case we'll probably need ecmarkup to generate sensible aria-labels for pretty much everything :-P

That they don't all return such records explicitly is something I find very confusing.

My preferred understanding is that every abstract operation that describes runtime semantics returns a completion record. You can understand things like IsCallable in terms of the 6.2.2.2 semantics (hopefully temporary) that allow treating a completion record as a value when it makes sense to do so.

Member

bterlson commented May 17, 2016

FWIW I like the current punctuators although the ! vs. negation confusion is sometimes annoying.

I'm in the same boat, but if people are confused, it should be fixed.

I'm afraid they will end translated as "SQUARED DOT OPERATOR", in the middle of a sentence this is way more extra information than just "question mark", etc

To be fair, screen readers don't read the current punctuators at all (and in general the spec is miserable to use with a screen reader). A lot of work needs to be done to make this better, and I doubt it matters what sigil we use as in any case we'll probably need ecmarkup to generate sensible aria-labels for pretty much everything :-P

That they don't all return such records explicitly is something I find very confusing.

My preferred understanding is that every abstract operation that describes runtime semantics returns a completion record. You can understand things like IsCallable in terms of the 6.2.2.2 semantics (hopefully temporary) that allow treating a completion record as a value when it makes sense to do so.

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson May 17, 2016

Member

FWIW I like the current punctuators although the ! vs. negation confusion is sometimes annoying.

I'm in the same boat, but if people are confused, it should be fixed.

I'm afraid they will end translated as "SQUARED DOT OPERATOR", in the middle of a sentence this is way more extra information than just "question mark", etc

To be fair, screen readers don't read the current punctuators at all (and in general the spec is miserable to use with a screen reader). A lot of work needs to be done to make this better, and I doubt it matters what sigil we use as in any case we'll probably need ecmarkup to generate sensible aria-labels for pretty much everything :-P

That they don't all return such records explicitly is something I find very confusing.

My preferred understanding is that every abstract operation that describes runtime semantics returns a completion record. You can understand things like IsCallable in terms of the 6.2.2.2 semantics (hopefully temporary) that allow treating a completion record as a value when it makes sense to do so.

Member

bterlson commented May 17, 2016

FWIW I like the current punctuators although the ! vs. negation confusion is sometimes annoying.

I'm in the same boat, but if people are confused, it should be fixed.

I'm afraid they will end translated as "SQUARED DOT OPERATOR", in the middle of a sentence this is way more extra information than just "question mark", etc

To be fair, screen readers don't read the current punctuators at all (and in general the spec is miserable to use with a screen reader). A lot of work needs to be done to make this better, and I doubt it matters what sigil we use as in any case we'll probably need ecmarkup to generate sensible aria-labels for pretty much everything :-P

That they don't all return such records explicitly is something I find very confusing.

My preferred understanding is that every abstract operation that describes runtime semantics returns a completion record. You can understand things like IsCallable in terms of the 6.2.2.2 semantics (hopefully temporary) that allow treating a completion record as a value when it makes sense to do so.

@jmdyck

This comment has been minimized.

Show comment
Hide comment
@jmdyck

jmdyck May 18, 2016

Collaborator

@annevk:

If you go as far as having Unbox and Check, then perhaps they should simply be abstract operations?

Unbox could be an abstract operation, but Check has to be a shorthand (i.e., macro). If you try to write it as an abstract operation, then when it detects an abrupt completion and returns, it's just returning from Check, not from the caller.

Collaborator

jmdyck commented May 18, 2016

@annevk:

If you go as far as having Unbox and Check, then perhaps they should simply be abstract operations?

Unbox could be an abstract operation, but Check has to be a shorthand (i.e., macro). If you try to write it as an abstract operation, then when it detects an abrupt completion and returns, it's just returning from Check, not from the caller.

@leobalter

This comment has been minimized.

Show comment
Hide comment
@leobalter

leobalter May 20, 2016

Member

As I mentioned before, I don't like the idea of using Unbox, after thinking about it over the days and heavily based on the discussion on this issue, I believe the following might work as good replacements:

  • ? becomes a check shorthand/macro
  • ! becomes an assert shorthand/macro.
Member

leobalter commented May 20, 2016

As I mentioned before, I don't like the idea of using Unbox, after thinking about it over the days and heavily based on the discussion on this issue, I believe the following might work as good replacements:

  • ? becomes a check shorthand/macro
  • ! becomes an assert shorthand/macro.
@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache May 21, 2016

Contributor

? becomes a check shorthand/macro
! becomes an assert shorthand/macro.

That implies conventional implicit unboxing. In that case, we should make sure that the few places that use the unboxed completion records are marked with explicit non-unboxing, e.g.: « Let foo be the Completion Record returned by ... »

Contributor

claudepache commented May 21, 2016

? becomes a check shorthand/macro
! becomes an assert shorthand/macro.

That implies conventional implicit unboxing. In that case, we should make sure that the few places that use the unboxed completion records are marked with explicit non-unboxing, e.g.: « Let foo be the Completion Record returned by ... »

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic May 21, 2016

Member

I'm in the same boat, but if people are confused, it should be fixed.

How many people are confused?

Member

domenic commented May 21, 2016

I'm in the same boat, but if people are confused, it should be fixed.

How many people are confused?

@bzbarsky

This comment has been minimized.

Show comment
Hide comment
@bzbarsky

bzbarsky May 22, 2016

Everyone I've talked to who has to look at the algorithms involved and wasn't involved in the initial discussions. That's 3 or 4 people so far.

bzbarsky commented May 22, 2016

Everyone I've talked to who has to look at the algorithms involved and wasn't involved in the initial discussions. That's 3 or 4 people so far.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache May 23, 2016

Contributor

Given that boxing the returned value is usually implicit, it may be fine to have implicit unboxing:

  • ? Foo() → return-if-abrupt Foo()
  • ! Foo() → assert-not-abrupt Foo()
  • Foo() → get-completion Foo()
Contributor

claudepache commented May 23, 2016

Given that boxing the returned value is usually implicit, it may be fine to have implicit unboxing:

  • ? Foo() → return-if-abrupt Foo()
  • ! Foo() → assert-not-abrupt Foo()
  • Foo() → get-completion Foo()
@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb May 23, 2016

Member

What's the current thinking about static semantics related abstract operations. They must never produce an abrupt completion and hence don't really need to use completion records and callers don't really need to unbox the result.

Is the intent to switch handle them switch them to also using completion records/unboxing but with the knowledge that they never produce abrupt completions?

Member

allenwb commented May 23, 2016

What's the current thinking about static semantics related abstract operations. They must never produce an abrupt completion and hence don't really need to use completion records and callers don't really need to unbox the result.

Is the intent to switch handle them switch them to also using completion records/unboxing but with the knowledge that they never produce abrupt completions?

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson May 23, 2016

Member

@allenwb My weak preference is to say that algorithm steps labeled "static semantics" don't return completion records, which means that static semantics don't need to uselessly use the !/?/whatever syntax. However I can understand not wanting to have two types of algorithms with different behavior. What do you think?

Member

bterlson commented May 23, 2016

@allenwb My weak preference is to say that algorithm steps labeled "static semantics" don't return completion records, which means that static semantics don't need to uselessly use the !/?/whatever syntax. However I can understand not wanting to have two types of algorithms with different behavior. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment