Closed showell closed 13 years ago
.
or []
, except it's applied to the prototype of the left operand instead of the left operand itself.You can write non-trivial programs without all optional syntax. That's why it's called optional. Don't know what you mean about the compiler avoiding it:
$ grep -r :: src
src/nodes.coffee: Array::push.apply ifn.body.properties, @properties
src/nodes.coffee:# A `.` access into a property of a value, or the `::` shorthand for
src/nodes.coffee: filterImplicitObjects: Call::filterImplicitObjects
src/nodes.coffee: jumps: While::jumps
src/lexer.coffee: (prev = last @tokens) and (prev[0] in ['.', '?.', '::'] or
src/lexer.coffee:LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?![.\d]) | :: ) ///
src/lexer.coffee:CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER']
src/rewriter.coffee: return yes if tag in ['.', '?.', '::'] and @tag(i - 1) is 'OUTDENT'
src/grammar.coffee: o ':: Identifier', -> [(new Access new Literal 'prototype'), new Access $2]
src/grammar.coffee: o '::', -> new Access new Literal 'prototype'
src/grammar.coffee: ['left', '.', '?.', '::']
$ grep -r \\.prototype\\. src
src/nodes.coffee: Array.prototype.indexOf || function(item) {
src/nodes.coffee: hasProp: -> 'Object.prototype.hasOwnProperty'
src/nodes.coffee: slice : -> 'Array.prototype.slice'
$
The only 3 uses of .prototype.
are in JS.
A::b
and A#b
are often used to reference instance methods or class methods in documentation. It's natural to actually accept it as executable code.@michaelficarra The places where the CS compiler references "::" in grammar.coffee, lexer.coffee, and nodes.coffee don't illustrate the utility of "::"; they illustrate the cost of supporting it. Likewise for the two places it shows up in the comments in nodes.coffee. All told, the compiler only uses "::" as an actual feature in two places, "Call::filterImplicitObjects" and "While::jumps".
I agree that the syntax has some convenience and learnability, but I think we differ on how high the bar should be before you introduce new syntax.
The CS compiler is over 4000 lines of code. It uses "::" twice. Using that small sample set, I'd say the syntax doesn't have much use.
s/introduce new syntax/keep around syntax/
The fact that "::" already exists obviously makes it harder to eliminate it, but if it's really just a legacy bridge from JS, as I believe, then it's gonna be a wart in the future, and the earlier you eliminate it, the better.
I think this issue is a non-starter, @showell. ::
is widely regarded as one of CoffeeScript's handier sugars. Closing unless I hear a "+1" soon...
@TrevorBurnham: agreed.
I expect this to be closed quickly, but it might be useful to have on the record. I think "::" should be deprecated.
See also issue 1601