Editing
Elixir Style Guide
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Elixir Style Guide == This style guide provides guidelines for writing clean and maintainable Elixir code. Adhering to these guidelines will not only improve the readability of your code but also promote consistency across projects. Following a consistent style in your Elixir codebase will make it easier for other developers to understand and contribute to your project. === Naming Conventions === - Use descriptive and meaningful names for variables, functions, and modules - Use snake_case for atoms and functions - Use CamelCase for modules and structs === Formatting === - Indent using 2 spaces - Use braces to wrap multiline function bodies - Place closing braces on the same line as the opening braces - Use a single-line comment (`#`) for comments that fit in one line - Use a multi-line comment (`"""`) for comments spanning multiple lines === Modules and Functions === - Use module attributes (`@`) to document and provide metadata - Define functions in a consistent order: public functions before private functions - Use pattern matching to define multiple function clauses === Error Handling === - Use `with` statements to handle multiple potential errors - Make use of the `{:ok, result}` and `{:error, reason}` tuple convention for function returns === Concurrency === - Opt for higher-level constructs like GenServer and Task when dealing with concurrency - Use message passing and pattern matching for communication between processes - Leverage supervisors for fault tolerance and graceful error handling === Testing === - Write comprehensive tests to verify code functionality - Use the ExUnit framework for writing unit tests - Organize tests into test cases and test suites === Documentation === - Provide meaningful and concise documentation for modules, functions, and types - Use Markdown syntax for formatting documentation === Resources === * [https://elixir-lang.org/docs/master/elixir/StyleGuide.html Elixir Style Guide] * [https://hexdocs.pm/ex_unit/ ExUnit Documentation] * [https://hexdocs.pm/elixir/ Elixir Documentation] == See Also == * [[Elixir Basics]] * [[Elixir Concurrency]] * [[Elixir Testing]] == References == [[Category:Elixir Documentation]]
Summary:
Please note that all contributions to Elixir Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Elixir Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information