livebook-dev / kino

Client-driven interactive widgets for Livebook
Apache License 2.0
372 stars 65 forks source link

Proposal: Add shortcut to nothing in Kino.Shorts #473

Closed christhekeele closed 1 month ago

christhekeele commented 1 month ago

As I make more sophisticated Kino UIs:

In the spirit of Kino.Shorts reducing the times you have to type Kino, I thought a shortcut function might make sense. For a use-case extracted from a pattern I've used several times now, see the second example in the function docs.

The name I've chosen here (output_nothing) is debatable:

christhekeele commented 1 month ago

I do feel like including a verb in the function name improves the readability (here and in most function names). Kino.nothing() is a noun because it is returning the special t:Kino.nothing atom, but once aliased just calling nothing() tells me nothing about what the function call accomplishes.

I am not sure I like nothing/1 because it gives the impression something is done with the argument.

Perhaps a different verb would make you feel more comfortable with it, say ignore_output/1?

josevalim commented 1 month ago

The issue is that it is inconsistent with everything else. audio, mermaid, etc are all outputs, we don't label any of them.

Perhaps a different verb would make you feel more comfortable with it, say ignore_output/1?

Not really, it has no relationship with the input in any case. :)

christhekeele commented 1 month ago

The issue is that it is inconsistent with everything else. audio, mermaid, etc are all outputs, we don't label any of them.

I see what you mean, they are all nouns too. Despite that, I still like the readable verb form and /1 arity, since the fact that the function does not return something kino-renderable makes it kind of a non-entity in Kino terms (and therefore not a noun). While Kino.render(nothing()) reads nicely, providing the verb context, just nothing() does not to me.

If you're not sold on verb-name or arity-1, though, I think it's fine to close this PR, as the exact same thing as your proposed alterations can be accomplished with more clarity via import Kino, only: [nothing: 0]

josevalim commented 1 month ago

I am ok with adding nothing/0 as a shortcut, as the functions here are only meant to be shortcut, not new functionality. But if you don't see a value in that, we can close this.