New Java proposal: JEP draft explores Java syntax with hyphenated keywords
What’s new for Java? Discussion and JEP drafts move us forward day by day. One JEP draft suggests a new solution: Keyword Management for the Java language. See what its goal are, what it plans to accomplish, and what potential alternatives there are.
Since the last update from Brian Goetz, one of the Chief Java Language Architects at Oracle, JDK development steadily moves forward. New JEP drafts have been added for consideration and the community continues discussing their potential and the evolution of Java.
Let’s take a closer look at a JEP “Keyword Management for the Java Language” by Alex Buckley and see what propositions it makes for future of the JDK.
Keyword Management for the Java Language
In the OpenJDK discussion, Buckley refers to a technique suggested by Brian Goetz regarding generating new keywords without running the risk of breaking existing programs.
The idea is that in order to make sure that code is legible, but also compatible with new features and existing programs, there must be a new kind of keyword. Buckley references JEP 352, Switch Expressions, as a language feature already prepared to use this potential idea.
This informal draft JEP proposes the idea of a hyphenated keyword. These keywords would be a compound of pre-existing keywords and identifiers.
Alex Buckley lists the intended goals and non-goals:
- Explore the syntactic options open to Java language designers for denoting new features.
- Solve the perpetual problem of keyword tokens being so scarce and expensive that language designers have to constrain or corrupt the Java programming model to fit the keywords available.
- Advise language designers on the style of keyword suited to different kinds of features.
- In any proposal for new elements of Java syntax, it is important to avoid being influenced by the (often strawman) syntax of language features presently in development.
- It is not a goal to optimize new elements of Java syntax for ease of implementation by compiler developers.
The next step in language evolution?
Not all Java developers will approve of the idea of bringing hyphenated keywords to the language. It would require an unfamiliar change to the JDK. However, would it be a worthwhile change?
How else can the Java language address its current keyword challenge? The JEP draft mentions potential alternatives and examples.
Perhaps the illusion of creating a new keyword is possible by reclassifying in variable declarations, or reclassifying the identifier module as a keyword in module declarations. Kotlin allows a keyword to be used as an identifier by enclosing the keyword in backticks.
Meanwhile, the community discussions regarding the benefits of this proposal for the JDK continue. Some of the response is positive, and agrees that this is the next natural phase of the JDK.
John R. Rose from Oracle notes that, “This sort of thing is unavoidable in language evolution, isn’t it? Any future extension will have to avoid ground already by past extension…One nice thing about Alex’s proposal is that, if adopted this year, IDEs can immediately syntax-color all possible hyphenated proper keywords (and maybe even most of the conditional ones).”
Time will tell if this draft makes it out of its current stage and into the next phase of Java’s journey.
Read more about the JEP, its potential alternatives and risks. What do you think about this draft so far?