twosigma / beakerx

Beaker Extensions for Jupyter Notebook
http://BeakerX.com
Apache License 2.0
2.8k stars 381 forks source link

Make a JShell kernel #5428

Open dsblank opened 7 years ago

dsblank commented 7 years ago

Java9 is about ready to release its RC1, with the final version due out in about a month (July 2017):

http://openjdk.java.net/projects/jdk9/

It would be fairly easy to make a beakerx JShell-based kernel:

import jdk.jshell.*;

public class JShellKernel {
    JShell js;
    JShellKernel() {
    js = JShell.create();
    }

    public void eval(String code) {
    js.eval(code);
        // etc.
    }
}

There are differences between a JShellKernel and the current beakerx JavaKernel (this is to the best of my knowledge, not being an expert in JShell nor Beakerx JavaKernel):

  1. JShell can evaluate snippets and expressions (eg, "1 + 1"). See http://download.java.net/java/jdk9/docs/api/jdk.jshell-summary.html. JavaKernel requires each cell to be a complete set of Java statement(s).
  2. JShell has optional semicolons; JavaKernel does not.
  3. JShell doesn't support return as a snippet; JavaKernel does support return.
  4. JShell allows variables to persist between evals; JavaKernel variables live only for the life of the cell.
  5. JShell allows "forward reference": code may reference items not defined yet. This allows writing code that has co-dependencies. I don't think this type of code development is possible in JavaKernel.

From a pedagogical standpoint, none of these differences may be desired, and the JavaKernel may be prefered in the classroom. For example, if students learn that they don't need semicolons, then there is some cognitive overhead when transitioning to full Java.

On a related note, parts of Java9 JShell might be usable in the JavaKernel, if you switch to java9. For example, JShell also has functionality for code-completion.

scottdraves commented 7 years ago

Yup, agreed, when we switch to java9. We had an issue for this in classic Beaker: https://github.com/twosigma/beakerx/issues/3585 That switch might be a long way away however.

pdeitel commented 7 years ago

Hi All, Curious if any work has been done on incorporating Java 9 support in BeakerX yet. Thanks.

scottdraves commented 7 years ago

No work has been done but we are closer now that java9 is out. Normally we get the jdk from conda, and java9 is not there yet afaik: https://github.com/conda-forge/openjdk-feedstock/issues/21 We could do the development without that though. I think best would be to support it as an additional JShell kernel, and leave our Java kernel as it is.

dsblank commented 7 years ago

I agree: a JShell Kernel would be a different beast, and the choice of which to use should be left to the user. There are pros and cons to both. (I really like the idea of a JShell kernel... our early prototype [1] can be quite useful, and I see some other new java9 kernel projects. But building on the Beaker infrastructure would be great!)

[1] - https://jupyter.brynmawr.edu/services/public/dblank/Experiments/Java9.ipynb

pdeitel commented 6 years ago

Just checking whether any more work has been done on Java 9 JShell kernel integration. If so, I’d love to play around with it and provide feedback.

Also, do you know of a Jupyter kernel that fully supports Java 9?

Best, Paul

On Nov 8, 2017, at 11:21 AM, Doug Blank notifications@github.com wrote:

I agree: a JShell Kernel would be a different beast, and the choice of which to use should be left to the user. There are pros and cons to both. (I really like the idea of a JShell kernel... our early prototype [1] can be quite useful, and I see some other new java9 kernel projects. But building on the Beaker infrastructure would be great!)

[1] - https://jupyter.brynmawr.edu/services/public/dblank/Experiments/Java9.ipynb https://jupyter.brynmawr.edu/services/public/dblank/Experiments/Java9.ipynb — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/twosigma/beakerx/issues/5428#issuecomment-342870123, or mute the thread https://github.com/notifications/unsubscribe-auth/AEVrtUf-fw1AQ0CN2nWStEyEvwGXz3i4ks5s0dUPgaJpZM4Nv6PD.

scottdraves commented 6 years ago

We are blocked on conda supporting java9. See the above feedstock issue.

pdeitel commented 6 years ago

That’s what I thought. And no feedback from them on when they might add Java 9?

On Feb 11, 2018, at 11:14 AM, Scott Draves notifications@github.com wrote:

We are blocked on conda supporting java9. See the above feedstock issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/twosigma/beakerx/issues/5428#issuecomment-364763406, or mute the thread https://github.com/notifications/unsubscribe-auth/AEVrtX3BYlONI47A9237xFCxm4-yMFfYks5tTxIBgaJpZM4Nv6PD.

scottdraves commented 6 years ago

Correct. Maybe voting for the issue will help?

On Feb 11, 2018 12:22 PM, "pdeitel" notifications@github.com wrote:

That’s what I thought. And no feedback from them on when they might add Java 9?

On Feb 11, 2018, at 11:14 AM, Scott Draves notifications@github.com wrote:

We are blocked on conda supporting java9. See the above feedstock issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/twosigma/beakerx/issues/5428#issuecomment-364763406>, or mute the thread https://github.com/notifications/unsubscribe-auth/ AEVrtX3BYlONI47A9237xFCxm4-yMFfYks5tTxIBgaJpZM4Nv6PD.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/twosigma/beakerx/issues/5428#issuecomment-364769084, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6yFTH4PlAK7Fe6xexCUIDux4yRrH3pks5tTyHBgaJpZM4Nv6PD .

benmccann commented 5 years ago

I'm curious if this is something that might be prioritized soon since Conda has added Java 9 support now

benmccann commented 5 years ago

https://github.com/SpencerPark/IJava uses JShell and is MIT licensed in case it is helpful to have an example of another JShell kernel