Elixir: When to use .ex and when .exs files

后端 未结 3 922
悲哀的现实
悲哀的现实 2020-12-24 04:33

Elixir\'s documentation states that

In addition to the Elixir file extension .ex, Elixir also supports .exs files for scripting. Elixir treats both

3条回答
  •  执笔经年
    2020-12-24 04:58

    .ex is for compiled code, .exs is for interpreted code.

    ExUnit tests, for example, are in .exs files so that you don't have to recompile every time you make a change to your tests. If you're writing scripts or tests, use .exs files. Otherwise, just use .ex files and compile your code.

    As far as pros/cons, interpretation will take longer to execute (as elixir has to parse, tokenize, etc.), but doesn't require compilation to run. That's pretty much it - if the flexibility of running scripts is more important than optimized execution time, use .exs. Most of the time, you'll use .ex.

提交回复
热议问题