JEP proposed to target JDK 11: 330: Launch Single-File Source-Code Programs
Brian Goetz
brian.goetz at oracle.com
Mon May 21 15:41:33 UTC 2018
I think this is mostly a "glass 5% empty" argument. Let's retrace our
steps.
The primary purpose is providing a reduced-ceremony path for developing
and running simple programs. This streamlines learning (no need to
learn about compilers before you can run your first Hello World),
prototyping (the edit-run cycle is streamlined), and distribution
(simple programs can be distributed and without additional packaging or
tooling.) And all of this is accomplished without shebang support.
Shebang support is an additional feature provided for deploying
script-like programs -- which is necessarily _at the end of their
development phase_. This allows you to drop a Java source in the file
system, as part of the package installation process, as an executable.
That's great, but at this point, the program is now a deployment
artifact, not a development artifact. Adding the shebang line is the
"packaging" step. But shebang is surely secondary to the main goals of
this feature.
I agree than in an alternate world, we could have made different choices
around the goals, but I see no new evidence that we chose the wrong
design center. If pressed, I'd be more inclined towards _dropping
shebang completely_ than infecting the language with it, but I think the
present position is a more pragmatic compromise.
I am happy to take Volker's suggestion and add an explicit non-goal to
characterize the intended limits of shebang support.
On 5/17/2018 4:50 PM, Roman Kennke wrote:
> Am 17.05.2018 um 22:12 schrieb mark.reinhold at oracle.com:
>> The following JEP is proposed to target JDK 11:
>>
>> 330: Launch Single-File Source-Code Programs
>> http://openjdk.java.net/jeps/330
>>
>> Feedback on this proposal is more than welcome, as are reasoned
>> objections. If no such objections are raised by 23:00 UTC on Thursday,
>> 24 May, or if they're raised and then satisfactorily answered, then
>> per the JEP 2.0 process proposal [1] I'll target this JEP to JDK 11.
>>
>> - Mark
>>
>>
>> [1] http://cr.openjdk.java.net/~mr/jep/jep-2.0-02.html
>>
> I like this proposal.
>
> I have a question about the shebang support though. If I write a
> sourcefile Test.java like this:
>
> #!/usr/bin/java
>
> public class Test {
> public static void main(String[] args) {
> System.out.println("Hello");
> }
> }
>
> ... then it's not a valid Java source file anymore, and (currently)
> rejected by javac. I see that it is not relevant for the intended use
> because the java launcher would strip the first line (except for the
> newline). I still find it odd.
>
> In particular, it may end up confusing for the growing experience:
> - people who start learning Java using this single-source feature will
> find that shebang 'Java scripts' don't actually compile when passed to
> the Java compiler
> - the little Java script turns out to be 'too slow', hey, let's compile
> it. Oops, doesn't work.
> - the little Java scipt has grown to complicated and needs additional
> classes, but doesn't compile.
> - editors/IDEs might (rightly) flag it as errors
>
> etc
>
> I wonder if it might be reasonable to extend the JLS to allow for
> shebang support too? Or maybe even don't extend the JLS but make
> compilers behave nicely anyway? At the very least, there should be some
> language in the JEP that mentions this issue. It is a complication that
> seems more important than the mentioned "HelloWorld"-package with "java"
> classname.
>
> Best regards, Roman
>
More information about the jdk-dev
mailing list