Casing

Aliases, commonly used as module names, are an exception as they must be capitalized and written in CamelCase, like OptionParser. For aliases, capital letters are kept in acronyms, like ExUnit.CaptureIO or Mix.SCM.

Atoms can be written either in :snake_case or :CamelCase, although the convention is to use the snake case version throughout Elixir.

Generally speaking, filenames follow the snake_case convention of the module they define. For example, MyApp should be defined inside the my_app.ex file. However, this is only a convention. At the end of the day, any filename can be used as they do not affect the compiled code in any way.

Underscore (_foo)

Elixir relies on underscores in different situations.

For example, a value that is not meant to be used must be assigned to _ or to a variable starting with underscore:

iex> {:ok,_contents}=File.read("README.md")

Function names may also start with an underscore. Such functions are never imported by default:

Due to this property, Elixir relies on functions starting with underscore to attach compile-time metadata to modules. Such functions are most often in the __foo__ format. For example, every module in Elixir has an __info__/1 function:

The version without ! is preferred when you want to handle different outcomes using pattern matching:

caseFile.read(file)do{:ok,body}-># do something with the `body`{:error,reason}-># handle the error caused by `reason`end

However, if you expect the outcome to always to be successful (e.g. if you expect the file always to exist), the bang variation can be more convenient and will raise a more helpful error message (than a failed pattern match) on failure.

In other words, functions using the word "size" in its name will take the same amount of time whether the data structure is tiny or huge. Conversely, functions having "length" in its name will take more time as the data structure grows in size.