add a mix command to generate code enhanced with macros expanded (for better code comprehension and debugging aid)

40 views
Skip to first unread message

miwee

unread,
Mar 17, 2017, 12:47:26 AM3/17/17
to elixir-lang-core
While going through one of the threads, I found this:

defmodule MyAgent do
  use Agent, restart: :transient

  # Generated on: use Agent
  # def child_spec(opts) do
  #   %{id: MyAgent, start: {__MODULE__, :start_link, [opts]}, restart: :transient}
  # end

  def start_link(opts) do
    Agent.start_link(fn -> %{} end, opts)
  end

  ...
end

Notice the commented portion starting with "# Generated on: use Agent". The code generated by macro "use Agent" is neatly present as comments. Anyone can inspect the code and understand what is happening behind the scene.

Some details:
1) Widely used and straightforward macros like if, def, defmodule etc. are excluded. The focus should be on documenting only those macros, which are application specific (like use Ecto.Schema)
2) Whenever the command is run (let's call it "mix annotate"), it goes through source code directory (lib folder primarily) and recreates annotated code files (mixed with commented macro code) in a separate folder. It should not modify the existing source files.
3) Since macros usually take options, there can be a new option like "use Agent, annotate: true". This way only those macros are expanded which are explicitly marked for annotation.
4) Similarly there can be a module attribute like "@annotate true" or "@annotate false". This way individual modules can be explicitly marked for annotation.

thanks
miwee

José Valim

unread,
Mar 17, 2017, 4:08:39 AM3/17/17
to elixir-l...@googlegroups.com
We would recommend folks to develop this as a separate project and explore the design decisions on this space.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/2491efbe-55b3-4c95-be32-860a84b0a527%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages