Fwd: Hyphenated keywords and switch expressions

Brian Goetz brian.goetz at oracle.com
Fri Jan 11 12:47:56 UTC 2019


Received from the -comments list.

> Begin forwarded message:
> 
> From: Ben Evans <benjamin.john.evans at gmail.com>
> Subject: Hyphenated keywords and switch expressions
> Date: January 11, 2019 at 5:19:25 AM EST
> To: amber-spec-comments at openjdk.java.net
> 
> Hi EG members,
> 
> I had a couple of comments on hyphenated keywords.
> 
> First off, I think they're a great idea, if used judiciously. One of
> Java's great strengths when teaching it to beginners is the simplicity
> and explicit regularity of the grammar. A few more keywords, keeping
> clear the distinction between keywords and other language constructs,
> is IMO a good thing - especially when it allows us to tidy up and
> explicitly express language ideas that we currently can't.
> 
> For example, the lack of package-private as an explicit keyword is one
> of the most common sources of confusion and errors I see in new Java
> devs - especially those who already know other programming languages.
> If we are going to do hyphenated
> 
> Secondly, a question. Is it worth reconsidering the choice of keyword
> used for switch expressions with hyphenation in mind? I re-read the
> discussion about not wanting to see switch statements abandoned, and a
> lack of consistency by using a new match keyword (imposed by eminent
> domain), and I can see the validity of a lot of the points made.
> 
> However, with hyphenated keywords, we have other possibilities - so
> what about using something like switch-expr (or switch-expression)
> instead? With the rules:
> 
> 1. switch is only legal in statement form (the current Java 11 behaviour)
> 2. switch-expr is only legal for the expression form
> 
> To my mind, this helps in a few ways:
> 
> a) It maintains the cognitive connection between switch expressions
> and switch statements, and doesn't lead to the feeling that switch
> statements are abandonware
> b) It provides a clear clue to newcomers about the distinction between
> the two forms (bear in mind that beginners often don't develop a full
> grasp of the distinction between statements and expressions until they
> have gained some proficiency with the language. The differentiation of
> the keyword could help provide visual clues and avoid
> hard-to-understand-if-you're-a-newbie compiler errors when debugging)
> c) There is no cognitive overhead for experienced programmers.
> d) IDEs will easily be able to autodetect and offer to correct if the
> wrong keyword is used "Did you mean switch-expr instead of switch?"
> 
> I'd be really interested to hear what people think - the above is very
> much with my "teaching newbies" hat on, and I know that's far from the
> only concern here.
> 
> Cheers,
> 
> Ben

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20190111/31e48d19/attachment.html>


More information about the amber-spec-experts mailing list