-
Notifications
You must be signed in to change notification settings - Fork 3
Consider making left operand of -> optional #17
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
Comments
We split off the shorthand into a separate proposal for private fields because it seemed like a lot of people developed misleading mental models of the syntax ("great, it's lexical") and because we were concerned that another case where you have to think about |
I don't think we should "kick things down the field" in this effort. Either decide we want to include a certain feature or not. Part of the goal here is to finish the work on classes. Personally, I don't think I'd use the PrimaryExpression abbreviation for ->. I generally choose readability over writability. But I don't have serious concerns with this abbreviation. I'm not sure exactly what your "great, it's lexical" concern was (and it may be a more valid concern for #18). I would always teach about hidden names by starting with the binary form and stressing that the left operand supplies the object context for the right operand. Only then (and after practice using the binary form) would I introduce the unary form and strongly emphasize that it is just an abbreviation of the binary form for when the left operand is literally I also think the difference between -> as an operator and # as a prefix makes a difference. The symbology of an arrow suggests something on the left going towards the thing on the right. I expect this might cause novice readers to think a bit more about what belongs on the left when nothing is there. # on the other hands doesn't naturally suggest the need for anything on the left. |
I'd like to reach that goal too. Several times in the development of these proposals (including on this particular question about shorthand), I tried to make statements like, "we won't do this in the future", including this feature. Sometimes, I was able to get consensus on these things, but other times, I wasn't able to, even if I personally might judge that we're better without the feature. The only way I saw to get consensus while specifying a reasonable feature was to make design decisions but also make sure that space is available to expand things in various other directions. I'm not sure how to do do otherwise with a group of highly opinionated people and a process based on absolute consensus.
This is really the core of the question. The pedagogical idea that several people had was the opposite of what you describe: that About the ASI hazard mitigation: I find this syntax a little surprising, given how class BSTNode {
var parent, leftChild, rightChild;
hidden operate() {
this->leftChild
->rotateLeft()
->rightChild
->rotateRight();
}
hidden rotateLeft() {
/* ... */
return this;
}
hidden rotateRight() {
/* ... */
return this;
}
} |
@littledan Great example! I think that, with the hidden access operator |
Note that the same problem, in theory, exists for unary + and - but in practice I guess it isn't a problem because of how they are used. I find this a pretty compelling example that suggests we can't have the primary expression form, and that in general we can introduce any new operator that can be used as both a binary and an unary operator. |
Not how I'd teach it. I'd start with |
Standard.js and other such semicolon-lite style checkers flag missing |
Me neither. From here, the question is, how do we coordinate among teachers that they explain the more accurate mental model? And, by their judgement, how teachable/learnable is it? |
@BrendanEich so, the argument is that this hazard already exists for other operators and so really won't be a problem for people who use a tool-supported semi free style. And it's not a problem for people how use semis. It's still a problem for new people who don't know the pitfalls and don't have the tools. I guess that's just the JS world we've all helped to create. |
@littledan I'm not sure that's our responsibility, except when we're giving conference talks and such. Whatever we do there will be good teacher and bad teachers, got books and bad, ... |
@allenwb Yes, I made this point at the last TC39 meeting. JS has two semicolon styles, both require parsing linters for any serious project. Old news, people can and do deal. @littledan We can't pick teachers but we can analyze Law of Least Effort and other human-factors laws, whether by simulating usage or doing real user research. If teachers have to gradgrind their students away from attractive nuisances and least-energy paths through a design space, we've done something wrong already. |
I think that in this particular case, a prefix To expand on the example in the OP, I don't think developers coding with "standard.js" would want to write this: class C {
var x, y, z
constructor(a, b) {
->x = a
;->y = b
;->z = 0
}
} |
Historical trivia, The self language is called "self" because it's major syntactic deviation from Smalltalk is that expressions like
could be abbreviated like:
|
@zenparsing Touché, although it looks better to put semi at end in this case -- which of course totally undermines Standard style! In DM'ing with @littledan, we both noted the recurring desire (if not "hard requirement", Dan said that phrase, I think)) for a shorthand expressed by TC39, which was used to argue against In interest of widening that DM discussion, let me copy one thing I wrote there: "Good point about """ @littledan Oh that's a matter of giving ExpressionStatement a no-shorthand lookahead and that's it @littledan Almost any accident will be an early error @BrendanEich yes @littledan The disadvantage is having an edge case to think about @littledan Anyway I still suspect people would just get over # if we force it on them @BrendanEich I think aesthetics matter, also arguments from nearby languages The "giving ExpressionStatement a no-shorthand lookahead" solution does require Update: Apologies for issue-jacking a bit, we can certainly close this as wont-fix. I'm interested in helping in London in two weeks' time, so want to consider all options and constraints to put best foot forward. Can we abuse this issue for a little while to do that? |
@allenwb yes, Self's name rationale is another bit of quasi-evidence that |
In these threads, we're getting at something that we found out in the development of the With half a token, if you have a good story for why that's happening (e.g., "you include the I'm not sure if we should go against many people's strong intuition that we shouldn't use |
@BrendanEich of course the vast majority of Smalltalk programmers have been perfectly fine with the explicit
I seems like we're edging back towards the situation TC39 is already in with the current extended class definitions proposals and the same situation we found ourselves in starting in 2009 until we were able to form consensus around the max-min class proposal. As soon as we move beyond the most minimal set of functionality, we open the door for a multitude of sometimes conflicting features whose inclusion is based upon personal preferences rather than functional necessity. Preferences get expressed as requirements and ultimately consensus threatening "hard requirements" . At that point TC39 either deadlocks or starts playing the piecemeal, kick the ball down the field game with proposal proponents trying to get the pieces approved that will set them up for achieving their ultimate preference. There are many additional features that various TC39 members would prefer to be part of this proposal or part of any set of extensions to JS class definitions. To have any chance of success with this proposal we will have to resist them. Arguably, the only unique thing in this proposal is its focus on a very small set of use-cases that require engine level support. If we can't sell and stick to this minimalism I think this effort will fail. |
@allenwb JS has had no alternative to In any event, I expect |
@BrendanEich I had originally suggested in #5 using I don't think that fact that |
Again I'm not saying anything new or trying to trigger rehashing :-D. Just pleading to get ahead on the two big objections we'll face: why Sorry I missed " @zenparsing 's idea for supporting unqualified use of hidden names when their object context is this" -- link? |
@BrendanEich here: #18 |
Closing in preparation for public review. Feel free to continue discussion here; we may choose to re-open at a later time. |
Notably, Ruby, the main other Smalltalk descendant, also made In the status quo proposal, I agreed to separate the shorthand into its own proposal because I didn't think it was in conflict with the rest of the proposal, and didn't think the rest of the proposal significantly foreclosed the shorthand. I still feel strongly that we should eventually consider the shorthand again, and disappointed that this proposal seems less of a good fit for a shorthand (for the standard.js hostility reason Kevin raised in this thread and the confusion with lexical scoping raised in #17). In addition to the issues already raised in this thread, I find |
@BrendanEich said: "The this-> is tedious and cries out for shorthand."
We could make
this
on the left of -> optional by adding a production like to the grammar:PrimaryExpression : -> IdentifierName
However, that by itself would introduce an ASI hazard:
This can be eliminate by adding a line terminator restriction to:
MemberExpression : MemberExpression [no LineTerminator here] -> IdentifierName
CallExpression : CallExpression [no LineTerminator here] -> IdentifierName
This is consistent with how similar ASI hazard are already handled.
The text was updated successfully, but these errors were encountered: