Home

Awesome

The Elixir Style Guide

Table of Contents

Prelude

Liquid architecture. It's like jazz — you improvise, you work together, you play off each other, you make something, they make something.

—Frank Gehry

Style matters. Elixir has plenty of style but like all languages it can be stifled. Don't stifle the style.

About

This is community style guide for the Elixir programming language. Please feel free to make pull requests and suggestions, and be a part of Elixir's vibrant community.

If you're looking for other projects to contribute to please see the Hex package manager site.

<a name="translations"></a> Translations of the guide are available in the following languages:

Formatting

Elixir v1.6 introduced a Code Formatter and Mix format task. The formatter should be preferred for all new projects and source code.

The rules in this section are applied automatically by the code formatter, but are provided here as examples of the preferred style.

Whitespace

Indentation

Parentheses

The Guide

The rules in this section may not be applied by the code formatter, but they are generally preferred practice.

Expressions

Naming

This guide follows the Naming Conventions from the Elixir docs, including the use of snake_case and CamelCase to describe the casing rules.

Comments

Comment Annotations

Modules

Documentation

Documentation in Elixir (when read either in iex with h or generated with ExDoc) uses the Module Attributes @moduledoc and @doc.

Typespecs

Typespecs are notation for declaring types and specifications, for documentation or for the static analysis tool Dialyzer.

Custom types should be defined at the top of the module with the other directives (see Modules).

Structs

Exceptions

Collections

Strings

Regular Expressions

No guidelines for regular expressions have been added yet.

Metaprogramming

Testing

Resources

Alternative Style Guides

Tools

Refer to Awesome Elixir for libraries and tools that can help with code analysis and style linting.

Getting Involved

Contributing

It's our hope that this will become a central hub for community discussion on best practices in Elixir. Feel free to open tickets or send pull requests with improvements. Thanks in advance for your help!

Check the contributing guidelines for more information.

Spread the Word

A community style guide is meaningless without the community's support. Please tweet, star, and let any Elixir programmer know about this guide so they can contribute.

Copying

License

Creative Commons License This work is licensed under a Creative Commons Attribution 3.0 Unported License

Attribution

The structure of this guide, bits of example code, and many of the initial points made in this document were borrowed from the Ruby community style guide. A lot of things were applicable to Elixir and allowed us to get some document out quicker to start the conversation.

Here's the list of people who have kindly contributed to this project.

<!-- Links -->