Java features
Brian Goetz
brian.goetz at oracle.com
Mon Jun 12 19:15:46 UTC 2023
Hi Tom;
This isn't really the right forum for this, but I can provide some quick
answers.
First, let me speak to the claim that Java hasn't taken the approach of
"adopting features from other languages". I think this claim is
problematic in a number of dimensions.
There is really no such thing as "adopting a feature from another
language" in the first place; every feature interacts with other
features in the language, and so even if one wants to have a feature "as
much like X from language Y as possible", it still must be the subject
of a clean-sheet design -- otherwise it will look bolted on the side
(because it will have been.) Think of it as an organ transplant; the
hard part is reconnecting all the small connections.
So rather than think about adopting _features_, it is instead more
profitable to _draw inspiration_ from things we observe in other
environments. And very often, the inspiration comes not from a specific
feature in language X, but from the places that X drew its inspiration
from. (Sometimes this chain can be followed for several hops.)
I don't quite know where you would get the idea that Java doesn't draw
inspiration from elsewhere; I can assure you that we have drawn
extensive inspiration from other languages and from the larger PL
literature base -- as I would expect most other languages to do. But we
are also mindful that not every feature in every language is worthy of
being emulated.
To your concrete points, both of these features were extensively
considered -- and explicitly rejected as poor ideas for Java. During
Project Lambda, the weaknesses of extension methods were extensively
discussed. During Project Loom, the weaknesses of async/await were
similarly discussed at length. That Java doesn't have this feature is
not because we're unaware of them, or because we're afraid of copying
them -- they're just not good enough ideas.
Sometimes programming languages do things that are superficially
interesting, but turn out to be bad ideas. Java has learned from the
experiences of other languages with respect to these two particular
ideas, and what we learned was that these features cause at least as
many problems as they solve.
On 6/10/2023 1:46 AM, Tom Rosenfeld wrote:
>
> Hello Everyone,
>
> I hope this is an appropriate forum for the thoughts I'd like to share
> on Java. If not, I would appreciate guidance as to the most fitting
> venue for such a discussion.
>
> Currently, I am contemplating two main points related to programming
> languages, specifically in relation to Java. First, it seems that many
> languages frequently adopt features from each other, and I'm curious
> as to why Java hasn't taken a similar approach.
>
> In particular, I've been considering the potential benefits of
> integrating extension methods and async-await into Java. With
> extension methods, users could benefit from a more concise syntax and
> a more functionally expressive coding approach. The async-await
> feature, a staple in languages like C# or JavaScript, might even be a
> superior alternative to Structured Concurrency. For instance, consider
> the code in this post:
> https://www.infoq.com/news/2023/06/structured-concurrency-jdk-21/
>
> In C#, it might look something like this:
>
> public async Task<Response> HandleAsync() {
> Task<string> userTask = FindUserAsync();
> Task<int> orderTask = FetchOrderAsync();
> await Task.WhenAll(userTask, orderTask);
> return new Response(userTask.Result, orderTask.Result);
> }
>
> In comparison to the original, this version seems considerably
> shorter, clearer, and easier to read.
>
> I look forward to hearing your thoughts on this matter.
>
> Best,
>
> Tom
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/java-se-spec-comments/attachments/20230612/dd2c2723/attachment-0001.htm>
More information about the java-se-spec-comments
mailing list