Could we change the syntax for when clauses?
David Alayachew
davidalayachew at gmail.com
Mon Nov 28 21:49:58 UTC 2022
Hello Brian,
Thank you for the response. Also, apologies for the multiple branches -
sometimes pipermail confuses me.
> Contextual keywords have been a thing for a long time,
> so to some degree, its already no longer “within
> reach.” But I don’t think we should worry too much
> about a flood; each feature is carefully considered
> and we try to balance all the competing concerns.
Of course, but the number and scale of them have been ramping up sharply
lately. I agree that every decision made regarding contextual keywords was
well reasoned and thought through, I am only trying to raise the point that
the effort to carry this is getting heavier at a faster rate for parsing
folks.
> We agree that we should use them with care. I think
> where we disagree is the weights we assign in the
> balancing of the tradeoffs.
That makes sense. I think I understand the perspective that you are coming
from now - simplifying the developer experience by maximizing readability
and expressiveness while avoiding unnecessary verbosity or contradiction of
the user's existing mental model. For context, I am coming from the
perspective of making language analysis tools for the language as easy to
make and performant as possible. I also teach new developers how to code in
Java, and one of the consistent pain points has been learning when and
where a context dependent keyword is allowed. Both of these points are what
motivated me to make my original post.
> double-checking-that
This is a very helpful example. It sounds like you are saying it is the
wrong choice because it throws away the established mental model to create
a new meaning. (double as a number, versus double as in the phrase
double-checking)
To make sure that I understand it though, another example would be
something like this?
case Integer x while x > 0
Right? That would "check all the boxes", but would involve users throwing
away the definition to make room for another one. (while as in while LOOP,
versus while as in the english word to imply 2 things being true
simultaneously)
It also sounds like not only do we want something that checks all the
boxes, but almost reads like a sentence too. Understanding that, it helps
me see why "when" is a good fit.
> We aim for decisions that, ten years from now, don’t
> stand out. (We often struggle with Stroustrup’s rule
> here too.)
I never knew about Stroustrup's Rule, thank you. Here it is for those who
are also just learning it.
- For new features, people insist on LOUD explicit syntax.
- For established features, people want terse notation.
With the point being, what is explicit and helpful today becomes noisy and
verbose tomorrow. We should prioritize terse now, and then it will feel
natural later.
This makes a lot of sense. And in that case, I see why my suggestions
mostly don't meet the needs. There needs to be a delicate balance between
terse and expressive here.
> (In regards to using "if")
> This one was discussed at some length and was
> rejected with prejudice :)
I'll do some research and see if that one isn't lost to the sands of time
as well. If anyone has a link or a rough sense of timing, that would also
be helpful.
Alternatively, if anyone remembers the reason, I would love to know why. I
can pretty well guess, but want to confirm.
> (In regards to using "only-if")
> I will admit the last one “isn’t terrible”,
> though it definitely STANDS OUT (see
> Stroustrup’s Rule) and I suspect the
> ten-year test will prefer “when” pretty
> strongly.
After reading all of this, I can see how it might stand out. And looking at
the above points again, I also see why "only-if" is the best contender of
my suggestions.
- Doesn't deviate too far from an existing mental model
- Is somewhat terse
- Reads like a sentence
I still stand behind "only-if". That said, I definitely concede that, from
the everyday Java developer's perspective, "when" is the superior choice.
All the same, as the language inevitably grows and branches out into new
territory/use-cases, the need for stronger static analysis tools grows with
it. I'd like to avoid stepping in the way of that any more than necessary.
And I think the benefits gained are worth 2 more characters and a hyphen.
Thank you for your time and insight!
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221128/e6154350/attachment-0001.htm>
More information about the amber-dev
mailing list