elixir-idioms
A reference for writing idiomatic Elixir code aligned with BEAM architecture and OTP patterns. Covers GenServer, Supervisor, Task, Registry, pattern matching, and the core principles that make concurrent systems reliable—including eleven iron laws never to violate and decision trees for control flow, error handling, and process design.
Elixir Idioms teaches OTP patterns and BEAM architecture for writing concurrent, fault-tolerant systems.
AI-generated summary based on this skill's SKILL.md
Install
oliver-kriska/claude-elixir-phoenix/elixir-idioms · repository language: Python
git clone https://github.com/oliver-kriska/claude-elixir-phoenix
cp -r claude-elixir-phoenix/plugins/elixir-phoenix/skills/elixir-idioms ~/.claude/skills/elixir-idiomsnpx skillfed install oliver-kriska/claude-elixir-phoenix/elixir-idiomsFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What are elixir idioms and best practices for concurrent systems?
elixir-idioms teaches idiomatic Elixir code aligned with BEAM architecture and OTP patterns. Core practices include leveraging pattern matching over conditionals, using tagged tuples for error handling, embracing the pipe operator, and designing with supervision trees. The skill covers GenServer, Supervisor, Task, and Registry—the foundational abstractions for reliable concurrent systems—plus eleven iron laws never to violate and decision trees for choosing between control flow approaches, error strategies, and process types.
How do OTP patterns and GenServer, Supervisor work in Elixir?
elixir-idioms explains OTP patterns including GenServer for stateful processes, Supervisor for fault tolerance and process trees, and Task for fire-and-forget work. GenServer provides call/cast semantics and state management; Supervisor restarts failed children according to strategies (one_for_one, one_for_all, rest_for_one). Together they implement the 'let it crash' philosophy—processes fail and restart cleanly rather than accumulating corruption. The skill includes decision trees for when to use GenServer versus Agent or plain functions.
What is BEAM concurrency design and how does it differ?
elixir-idioms covers BEAM architecture—the Erlang virtual machine underlying Elixir—which uses lightweight processes and message passing instead of threads. Each process has its own heap and garbage collection; processes communicate asynchronously via mailboxes. This model eliminates shared-memory races and makes systems naturally scalable. The skill explains process model fundamentals, memory isolation, and how BEAM-aware design—supervision, pattern matching, and OTP abstractions—leverages these properties for fault tolerance and concurrency.
How should I handle errors in Elixir with tagged tuples?
elixir-idioms teaches error handling strategies centered on tagged tuples: {:ok, result} and {:error, reason}. This pattern is idiomatic across Elixir libraries and integrates with with/1 clauses for clean error propagation. The skill covers when to raise exceptions versus returning error tuples, supervision best practices for letting processes crash and restart, and anti-patterns like swallowing errors or over-defensive coding. Tagged tuples make error flows explicit and composable with pipe operators and pattern matching.
What are common elixir mistakes and anti-patterns to avoid?
elixir-idioms identifies anti-patterns including pattern matching over conditionals, overusing Agent when GenServer is needed, ignoring supervision trees, and defensive coding that masks failures. The skill includes eleven iron laws never to violate—core principles that protect reliability. It also covers when not to use the pipe operator, misuse of guards, and process design mistakes like blocking the scheduler or creating unbounded process trees. Decision trees help you recognize pitfalls and choose idiomatic alternatives.
When should I use Agent versus GenServer in Elixir?
elixir-idioms provides a decision tree for choosing between Agent, GenServer, Task, and plain functions. Agent is a minimal wrapper for simple state; GenServer adds call/cast semantics and lifecycle hooks for complex logic. Use Agent for read-modify-write operations; use GenServer when you need request-response patterns, multiple message types, or init/terminate callbacks. The skill explains trade-offs: Agent is simpler but less flexible; GenServer is more powerful but requires more boilerplate. Task suits one-off async work.
SKILL.md
rendered from the published skill — quoted content, verbatim
Elixir Idioms
Reference for writing idiomatic Elixir code with BEAM-aware patterns.
Iron Laws — Never Violate These
- NO PROCESS WITHOUT A RUNTIME REASON — Processes model concurrency, state, isolation—NOT code structure
- MESSAGES ARE COPIED — Keep messages small (except binaries >64 bytes)
- GUARDS USE
and/or/not— Never use short-circuit operators in guards (guards require boolean operands) - CHANGESETS FOR EXTERNAL DATA — Use
cast/4for user input,change/2for internal - RESCUE ONLY FOR EXTERNAL CODE — Never use rescue for control flow
- NO DYNAMIC ATOM CREATION —
String.to_atom(user_input)causes memory leak (atoms aren't GC'd) - @external_resource FOR COMPILE-TIME FILES — Modules reading files at compile time MUST declare
@external_resource - SUPERVISE ALL LONG-LIVED PROCESSES — Never bare
GenServer.start_link/Agent.start_linkin production. Use supervision
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 10 files
plugins/elixir-phoenix/skills/elixir-idioms/SKILL.md
plugins/elixir-phoenix/skills/elixir-idioms/references/anti-patterns.md
plugins/elixir-phoenix/skills/elixir-idioms/references/elixir-118-features.md
plugins/elixir-phoenix/skills/elixir-idioms/references/elixir-120-type-system.md
plugins/elixir-phoenix/skills/elixir-idioms/references/error-handling.md
plugins/elixir-phoenix/skills/elixir-idioms/references/mix-tasks.md
plugins/elixir-phoenix/skills/elixir-idioms/references/otp-patterns.md
plugins/elixir-phoenix/skills/elixir-idioms/references/pattern-matching.md
plugins/elixir-phoenix/skills/elixir-idioms/references/troubleshooting.md
plugins/elixir-phoenix/skills/elixir-idioms/references/with-and-pipes.md