scijava / scijava-jupyter-kernel

[RETIRED] Try IJava or BeakerX
Apache License 2.0
177 stars 42 forks source link

Some cells should not have outputs #68

Closed hadim closed 7 years ago

hadim commented 7 years ago

Consider the two following cells:

// Cell 1
variable = 50

// Cell 2
variable = 50
variable

Both cells output the same thing: 50.

In my opinion and in order to match the other Jupyter kernels default behavior, SJK should return null for Cell 1 and 50 for Cell 2.

In the case of Cell 1, the user only asks to assign 50 to a variable. It didn't ask to display that variable. In the case of Cell 2, the accepted and default way to display a variable in Jupyter is to write the variable name at the end of the cell.

When developing a complicated and long script/notebook, most of the time you don't want the cell to display something.

@ctrueden would you agree to have the kernel to match this behavior?

ctrueden commented 7 years ago

I have reservations about the kernel working that way—I actually think it is less elegant/convenient—but supposing we make this change for consistency with other Jupyter kernels: I am still not sure how we would implement that. Some script languages might not have differentiable states for the two cases above.

ctrueden commented 7 years ago

Two hacky ideas/approaches:

  1. If you declare #@output int result at the top, but then don't assign a value to result, I think the output will end up blank because we skip rendering of null outputs.

  2. Another way to suppress the output would be to write:

    variable = 50
    null
hadim commented 7 years ago

At the moment I am using (2) as a workaround. But I am pretty sure that was the default behavior of the first version of the kernel... So something probably changed since we've integrated the script processors mechanism (need to investigate more).

I understand that is more elegant in a notebook used for teaching or demonstration but when it is used as a development tool for prototyping it can become quickly annoying. I say that from my 5 years old experience using the IPython kernel in Jupyter.

That being said, using null is good enough for me at the moment.

hadim commented 7 years ago

I propose we don't worry too much about that now and if someone complains about this behavior then we can think about switching the default behavior to output nothing when a variable is assigned at the last line of the cell.

ctrueden commented 7 years ago

if someone complains about this behavior then we can think about switching the default behavior to output nothing when a variable is assigned at the last line of the cell.

Sounds good. Like I said, I'm not sure this will be technically easy to do, but either way, I'm good with waiting till someone complains. :smile: