JEP proposed to target JDK 11: 330: Launch Single-File Source-Code Programs

Mario Torre neugens at redhat.com
Fri May 25 10:18:23 UTC 2018


 On Fri, May 25, 2018 at 1:23 AM, Jonathan Gibbons
<jonathan.gibbons at oracle.com> wrote:
> Mario,

> Regarding your specific proposal for using "here" documents, I do not follow
> your argument that your example is better for being "proper Java, with all
> the benefits like debugging, IDE support etc.". At least to a casual
> observer, the shebang line and the couple of lines to invoke java using a
> "here" document look very similar: in both cases, there is a cryptic header
> followed by some Java source code. In both cases the file can be seen as a
> script that contains Java source code, as compared to a Java source file
> that is a script.

The difference is subtle, with the shebang the "#!" is part of the
java file, with the here syntax it isn't, that means every single line
you write is actually proper java. One is an invalid .java file
unrecognized by IDE and compilers, the other is a shell script.

The implication is that a developer that wants to embed it in a shell
script is more forced to think about the embedding as part of the
process of writing the utility, but can do so at a later stage with no
modifications and without introducing an incompatible java artefact
(which is great for reuse for instance).

You are right there's not much difference from an IDE point of view
though, except that again a .java class that is loaded in an IDE but
contains the "#!"line won't be valid and will be unrecognized, while a
shell script will be essentially seen as a shell script. I suspect
that java code that is mean to be embedded like this will likely be
small utilities, but there's nothing stopping someone from creating a
full applications in the IDE and then just embed it in a script. The
shebang in this case would be tying the two process too tightly, if we
only support the here documents we are decoupling things which is
better imho.

> As to the possible ways forward:
>
> * Support for "//!" is attractive but requires a manual or automated update
> to the underlying system, which is beyond our control.
>
> * Support for using "here" documents as you suggest is possible: it is
> ultimately more flexible than shebang lines, and should be advertised in the
> JEP, but it requires a more advanced understanding of shell, when much of
> the current focus is about simplifying the on-ramp to Java.

I would go with that and drop the shebang, I strongly suspect that
shebang will create long term problems we are not carefully
considering at this stage.

Cheers,
Mario
-- 
Mario Torre
Associate Manager, Software Engineering
Red Hat GmbH <https://www.redhat.com>
9704 A60C B4BE A8B8 0F30  9205 5D7E 4952 3F65 7898


More information about the jdk-dev mailing list