본문으로 건너뛰기
cccskills
무료GitHub에 공개

elixir-idioms

OTP/BEAM patterns and Elixir idioms — GenServer, Supervisor, Task; Use when designing processes or debugging BEAM…

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(10)

  • SKILL.md4.5 KB
  • references/anti-patterns.md4.6 KB
  • references/elixir-118-features.md3.6 KB
  • references/elixir-120-type-system.md6.0 KB
  • references/error-handling.md2.7 KB
  • references/mix-tasks.md2.9 KB
  • references/otp-patterns.md10.6 KB
  • references/pattern-matching.md1.9 KB
  • references/troubleshooting.md4.5 KB
  • references/with-and-pipes.md7.2 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Elixir Idioms

Reference for writing idiomatic Elixir code with BEAM-aware patterns.

Iron Laws — Never Violate These

  1. NO PROCESS WITHOUT A RUNTIME REASON — Processes model concurrency, state, isolation—NOT code structure
  2. MESSAGES ARE COPIED — Keep messages small (except binaries >64 bytes)
  3. GUARDS USE and/or/not — Never use short-circuit operators in guards (guards require boolean operands)
  4. CHANGESETS FOR EXTERNAL DATA — Use cast/4 for user input, change/2 for internal
  5. RESCUE ONLY FOR EXTERNAL CODE — Never use rescue for control flow
  6. NO DYNAMIC ATOM CREATION — String.to_atom(user_input) causes memory leak (atoms aren't GC'd)
  7. @external_resource FOR COMPILE-TIME FILES — Modules reading files at compile time MUST declare @external_resource
  8. SUPERVISE ALL LONG-LIVED PROCESSES — Never bare GenServer.start_link/Agent.start_link in production. Use supervision trees
  9. WRAP THIRD-PARTY LIBRARY APIs — Always facade external deps behind a project-owned module. Enables swapping without touching callers
  10. MIX TASKS START ONLY WHAT THEY NEED — Mix.Task.run("app.config") + Application.ensure_all_started/1, never Mix.Task.run("app.start") (boots the FULL tree: endpoint port, Oban consuming)
  11. CAPTURE LOCALE BEFORE SPAWNING — Gettext/CLDR locale is process-local. Read it in the caller and pass explicitly; a spawned Task/GenServer starts with the default locale

BEAM Architecture (Why Elixir Works This Way)

  • Processes are cheap (2.6KB) — Spawn liberally for concurrency/isolation
  • Complete memory isolation — No shared state, no locks needed
  • Messages are copied (except binaries >64 bytes) — Keep messages small
  • Per-process GC — No global GC pauses
  • "Let it crash" — Supervisors restart to known-good state

Core Principles

  1. Pattern match over conditionals — Function heads first, then case, then cond
  2. Tagged tuples for expected failures — {:ok, _}/{:error, _} for expected errors, raise for bugs
  3. Pipe operator for data transformation — Start with data, never pipe single calls
  4. Let it crash — Handle expected errors, crash on unexpected ones
  5. Explicit over implicit — Be clear about intentions

Quick Decision Trees

Control Flow

Need patterns? → case (or function heads)
Multiple operations? → with
Boolean conditions? → cond (multiple) or if (single)

Error Handling

Expected failure? → {:ok, _}/{:error, _} tuples
Unexpected/bug? → raise exception (let supervisor handle)
External library? → rescue (only here!)

OTP

Need state?
├─ No → Plain functions
├─ Simple get/update → Agent or ETS
├─ Complex messages/timeouts → GenServer
└─ One-off async → Task

Quick Patterns

# Pattern match in function head
def process(%{status: :active} = user), do: activate(user)
def process(%{status: :inactive} = user), do: deactivate(user)

# with for happy path
with {:ok, user} <- get_user(id),
     {:ok, order} <- create_order(user) do
  {:ok, order}
end

# Task for async
Task.Supervisor.async_nolink(TaskSup, fn -> work() end)
|> Task.yield(5000) || Task.shutdown(task)

Common Pitfalls

WrongRight
length(list) == 0list == [] or Enum.empty?(list)
list ++ [item][item | list] |> Enum.reverse()
String.to_atom(input)String.to_existing_atom(input)
spawn(fn -> log(conn) end)ip = conn.ip; spawn(fn -> log(ip) end)
unless conditionif !condition (unless deprecated in 1.18)

References

For detailed patterns, see:

  • references/pattern-matching.md - Pattern matching, guards, binary matching
  • references/otp-patterns.md - GenServer, Supervisor, Task, Registry
  • references/error-handling.md - Tagged tuples, rescue, with
  • references/with-and-pipes.md - When to use with and |> (idiomatic patterns)
  • references/troubleshooting.md - Production BEAM debugging (memory, performance, crashes)
  • references/anti-patterns.md - Common mistakes and fixes
  • references/mix-tasks.md - Mix task naming, option parsing, shell output
  • references/elixir-118-features.md - Duration module, dbg improvements (1.18+)
  • references/elixir-120-type-system.md - Gradual type checker, dynamic(), verified bugs as compile warnings (1.20+, OTP 27+)

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

analyze

무료

Analyze a legacy app in any language before rewriting it in Elixir: inventory, features as goals, why each mechanism exists, runtime topology, external contracts. Use to start or refresh a rewrite.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oliver-kriska/claude-elixir-phoenix5672026년 10월 17일 업데이트

architect

무료

Design the idiomatic Elixir architecture for a rewrite: set the compatibility bar (ADR-000), consult phx specialists on open questions, then build contexts, ledger and ADRs. Use after /rewrite:analyze.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oliver-kriska/claude-elixir-phoenix5672026년 10월 17일 업데이트

Ash Framework — resources, actions, policies, aggregates; Use when generating resources via mix ash.codegen, editing…

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oliver-kriska/claude-elixir-phoenix5672026년 10월 17일 업데이트

Ash Framework — resources, actions, policies, aggregates, calculations, AshPhoenix.Form, LiveView, migrations. Use when generating resources via mix ash.codegen, editing changes, checks, types, validations, or domain code interfaces.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oliver-kriska/claude-elixir-phoenix5672026년 10월 17일 업데이트

assigns

무료

Compatibility alias for the Elixir/Phoenix plugin's LiveView assigns audit. Invoke explicitly with /lv:assigns.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oliver-kriska/claude-elixir-phoenix5672026년 10월 17일 업데이트

Inspect LiveView socket assigns for memory bloat — missing temporary_assigns, unused assigns, unbounded lists needing streams, memory estimates. Use when LiveView memory grows or you need to add temporary_assigns.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oliver-kriska/claude-elixir-phoenix5672026년 10월 17일 업데이트

oliver-kriska의 스킬 모두 보기

이 스킬의 문제 신고