by networked · 3y ago · 0 comments
I wish more developers knew about single-file scripts with dependencies. People seem to only discover them accidentally through a language or runtime that has the support built in. It means Elixir will contribute to the awareness, but Elixir itself is niche. Maybe Deno and Bun, as JavaScript runtimes, will popularize them. Having a common term not specific to any language may help, as there doesn't seem to be one. It hinders search. "(Single-file) scripts with dependencies" is what I have settled on.
Edit: Added the Crystal example and the second paragraph.
Plus, seeing code like https://github.com/colinrymer/leftpad.ex/blob/8d2230bf094eed... is just fun:
defmodule Leftpad do
@moduledoc """
Remembering `String.rjust/3` can be difficult, so Leftpad provides you
another way to easily left pad/right justify your UTF-8 encoded binaries.
"""
@doc ~S"""
Provides basically the same functionality as [`String.rjust/3`](http://elixir-lang.org/docs/stable/elixir/String.html#rjust/3)
## Examples
iex> Leftpad.pad("foo", 5)
" foo"
iex> Leftpad.pad("foobar", 6)
"foobar"
iex> Leftpad.pad("1", 2, ?0)
"01"
"""
@spec pad(string :: String.t, count :: non_neg_integer, char :: char) :: String.t
def pad(string, count, char \\ 32), do: String.rjust(string, count, char)
end
Look at that one line doing all the work, and even it delegates it to another function. defdelegate pad(string, count, char \\ 32), to: String, as: :rjust