Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Conversation

christhekeele
Copy link
Contributor

As I make more sophisticated Kino UIs:

  • I find myself using Kino.Shorts more to streamline large complicated blocks of Elixir Kino UI code
  • I find myself invariably terminating those blocks with Kino.nothing() since I've taken control of the rendering process

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:

  • On one hand it is two characters longer than the function it is aliasing
  • On the other hand it reads more clearly and declaratively than scattering kind of context-less Kino.nothing()s at the end of code blocks

Copy link
Contributor

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go with nothing(). I am not sure I like nothing/1 because it gives the impression something is done with the argument. A nothing() alone in the last line is clearer IMO.

@christhekeele
Copy link
Contributor Author

christhekeele commented Oct 3, 2024

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
Copy link
Contributor

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
Copy link
Contributor Author

christhekeele commented Oct 3, 2024

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants