Commandex - Make complex actions a first class data type

Few notes / questions, mostly around naming or convenience:

  • If I end up using such a library I’d appreciate it if I had a convenience function that does both new() and run(). Something like create_and_run(), maybe? Or make_and_run()? Or simply start?
  • Not sure how intuitive the naming of params and data is. I’d be a bit more formal and christen them input and output.
  • Ditto for pipeline. I get it that you probably want Plug users to feel at home but IMO something like action is clearer.
  • In my eyes {:ok, %{user: user, password_hash: "123"}} and {:error, error_object_or_message} are more idiomatic Elixir. (Note that Ecto.Multi partially follows your pattern but still uses tuples.)

To recap, this is how I’d find the whole thing more readable:

defmodule RegisterUser do
  import Commandex

  command do
    input :email
    input :password

    output :password_hash
    output :user

    action :hash_password
    action :create_user
    action :send_welcome_email
  end

  ...action functions go here
end

Don’t take my criticism seriously if you like your naming. I am only giving you a pure anecdote on what I’d find more intuitive / readable.


Lastly, as a friendly competition, you can take a look at Opus (they seem to like your pipeline naming :wink: ).

3 Likes