Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

double dot syntax proposal #80

Closed
victornpb opened this issue Jan 17, 2019 · 20 comments
Closed

double dot syntax proposal #80

victornpb opened this issue Jan 17, 2019 · 20 comments
Labels
alternative syntax past ideas and discussions about alternative syntaxes

Comments

@victornpb
Copy link

victornpb commented Jan 17, 2019

Just a wild idea, after more than a year revisiting this:

Double dot .. is syntax error, so it could be possible to allow this syntax and avoid the problems with the ? character:

foo..bar.baz

obj.a..b..c

and since .[ is syntax error

foo.['bar']..a.['c']

a.['b'].['c']..d

pros:

  • Clean
  • Not much different than the original dot accessor, but at the same time visually distinguishable.
  • Somewhat consistent with == and the variant === (but opposite)

cons:

  • Not alike other languages�
  • somewhat misleading to mathematical ..

Another variant on the same idea is to use:
a,.b,.c,.d

I don't know it this would be ambiguous for the parser along with other structures tho

@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

That would mean we'd have ., .., and ..., all doing different things, and only a keystroke apart. Seems confusing to me.

@rinick
Copy link

rinick commented Jan 17, 2019

e4x use double dot operator, although it's deprecated, it's probably still not the time to introduce a syntax conflict with that

@Mouvedia
Copy link

For the record in E4X "the .. operator accesses all children no matter how deeply nested".

@claudepache
Copy link
Collaborator

e4x use double dot operator, although it's deprecated, it's probably still not the time to introduce a syntax conflict with that

For information, E4X was removed from Firefox (the only web browser that supported it) about 6 years ago.

@claudepache
Copy link
Collaborator

That would mean we'd have ., .., and ..., all doing different things, and only a keystroke apart. Seems confusing to me.

There is no confusion possible with ..., because it is used in a different syntactical context. We have even several instances of the same token meaning completely different things, (e.g., ( ) for grouping and for function invocation, / for division and for regexp literals), and this is not confusing because they are used in mutually exclusive contexts (except in one edge case related to defective ASI).

By contrast, = and == meaning two wildly different things is problematic (and a source of bugs), because they can be used in the same context.

I don’t think that the difference between . and .. is much more (or less) confusing than the difference between == and ===. Or, well, between . and .. in late E4X.

(Also, before someone else wastes a comment for it: The fact that 4..x is already valid today with the meaning of (4.).x is a non-issue, because (4)..x and (4.).x will have exactly the same effect.)

@victornpb
Copy link
Author

victornpb commented Jan 18, 2019

@claudepache Those are really good points!

The real issue is that we already used all symbols on a standard US keyboard, everything from now on will either lack ergonomics or visual clarity

@ljharb

This comment has been minimized.

@claudepache

This comment has been minimized.

@Zarel
Copy link

Zarel commented Jan 18, 2019

My real objection here is that this is unpopular, because we already voted (in #51) on what we prefer, and a?.b a?.[b] a?.(b) was our first choice, and no other choice received positive votes, and now that the committee has finally agreed to implement our first choice, considering other choices would set us back very far.

Other reasons to prefer a?.b over a..b:

  • ?. is what every other language uses
  • The ? character makes sense to be associated with optionals
  • The .. token is even more difficult to extend to optional call and optional dynamic property access
  • The .. token has historically meant "range" in other languages, and not much else

If we were starting from scratch, it'd be an interesting proposal, but I just see no reason to reconsider ?.

@ljharb

This comment has been minimized.

@claudepache

This comment has been minimized.

@ljharb

This comment has been minimized.

@claudepache

This comment has been minimized.

@ljharb

This comment has been minimized.

@Zarel

This comment has been minimized.

@jridgewell

This comment has been minimized.

@ljharb

This comment has been minimized.

@Mouvedia
Copy link

The .. token has historically meant "range" in other languages, and not much else

You are right, that's the clincher.

@nodkz
Copy link

nodkz commented Apr 5, 2019

@littledan maybe close this issue?

@victornpb
Copy link
Author

I agree

@claudepache claudepache added the alternative syntax past ideas and discussions about alternative syntaxes label Jun 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
alternative syntax past ideas and discussions about alternative syntaxes
Projects
None yet
Development

No branches or pull requests

8 participants