-
Notifications
You must be signed in to change notification settings - Fork 14
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
Violating TCP? #33
Comments
But, |
Yes, specifically:
Because |
So, then why should |
I'm not what you mean by "act like an expression". |
The So, am I to understand that this proposal is actually to create a special dialect of ECMAScript that only exists between the brackets of a |
@JHawkley it already does; see |
The code I provided was not intended to be executed in the context of |
"should not apply" seems like an arbitrary designation; eval is part of the language. |
|
No, the claim you highlighted does not say anything about statements, positive or negative. But it is immediately followed by one:
which holds.
They continue to be statements. They have completion values, which is already the case, but are not usable in expression position. But more broadly, it is true that the goal of this proposal is to allow you to use statements in expression position by wrapping them in
Separately, no, |
Indeed. But a statement is still not an expression, so the current behavior of statements within a
I wasn't surrounding my
To be clear, my argument is: The existence of Using this one thing to justify the behavior of |
Yes, it is; the spec includes Completion Records from evaluating every statement; it's just that it's currently only exposed for non-expressions in |
Yes, the spec includes the notion of completion values. But the issue is that other part: "it's just that it's currently only exposed for non-expressions in Developers don't build their applications in an Why not just expose completion-values for non-expressions everywhere? If the different semantics are applied everywhere, there is no TCP violation. As was already stated elsewhere, we don't need There could probably be a feature for opting in to it (and other breaking language features) with something like an The only other thing I would be comfortable with is to just formalize IIFEs. These are already the idiomatic way to solve the problem that It isn't as deep into expression-oriented programming as some people would like, but the language would continue to work the same and all the semantics and behaviors that a developer is already familiar with remain unchanged. All the problems with implementing the current Something like: const input = 2;
const command = do => {
switch(input) {
case 1: return "run";
case 2: return "jump";
default: return "idle";
}
} This would be a very familiar syntax for any developer familiar with arrow-functions. And to avoid function-call overhead, you just assert that the body of the But, this discussion has so far not convinced me that the current proposal would be a good change for ECMAScript. I definitely want something like this; I'm a Scala developer so I know how nice expression-oriented programming is, but the current implementation feels too hazardous. The One of these two options would be much more responsible. |
The point you bring up is valid, but not a violation of TCP. do expressions do not change any semantics of the surrounding language. It's literally like The real issue you're having is that to most users of JS, statements have no "return" value. But even in this case, it has always been exposed in one way or another. The language has |
Aye, I now agree. After analyzing it for a day, I realize my misunderstanding. Since I no longer consider this an issue, I suppose I'll close this. However, I did come to some new conclusions and wrote up a document describing them. I'll put these into a new issue, though. It's a long read, but I hope it will provide useful information. |
Based on what I've seen of the Babel plugin and the examples provided here, I feel that the
do
expression is causing a massive violation of Tennant's Correspondence Principle. Let me go through an exercise to try and explain my concerns.The proposal currently asserts the following:
do { <expr>; }
is equivalent to<expr>
So, then these two blocks should evaluate to the same value.
do { if (true) "foo"; else "bar"; }
(if (true) "foo"; else "bar";)
But they do not. Refactoring the contents of the
do
out changes the behavior of theif-else
statement. Inside thedo
it evaluates to "foo" while outside thedo
it becomes a syntax error.This would mean that:
do { if (<cond>) <a>; else <b>; }
is not equivalent toif (<cond>) <a>; else <b>;
...and that is a contradiction of the original assertion.
Am I just misunderstanding something here?
The text was updated successfully, but these errors were encountered: