Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

elixir-idioms

/elixir-idioms

Opisuje wzorce OTP i BEAM oraz idiomy Elixira: GenServer, Supervisor, Task, Registry, dopasowanie wzorców i łańcuchy with przy projektowaniu procesów.

Licencja
MIT
Ostatnia zmiana repozytorium
22.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
10
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Opisuje wzorce OTP i BEAM oraz idiomy Elixira: GenServer, Supervisor, Task, Registry, dopasowanie wzorców i łańcuchy with przy projektowaniu procesów.

Oryginalny opis (EN)

OTP/BEAM patterns and Elixir idioms — GenServer, Supervisor, Task, Registry, pattern matching, with chains, pipes. Use when designing processes or debugging BEAM issues.

Jak działa

  1. Iron Laws — Never Violate These
  2. BEAM Architecture (Why Elixir Works This Way)
  3. Core Principles
  4. Quick Decision Trees
  5. Quick Patterns
  6. Common Pitfalls
  7. References
Sekcje z nagłówków SKILL.md, w oryginale · 105 linii, 609 słów
Podgląd SKILL.md
---
name: elixir-idioms
description: "OTP/BEAM patterns and Elixir idioms — GenServer, Supervisor, Task, Registry, pattern matching, with chains, pipes. Use when designing processes or debugging BEAM issues."
effort: medium
user-invocable: false
---

# 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

```elixir
# 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

| Wrong | Right |
|-------|-------|
| `length(list) == 0` | `list == []` 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 condition` | `if !condition` (unless deprecated in 1.18) |

## References

For detailed patterns, see:

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

Wersje

RepozytoriumWynikLicencja
Ta strona · oliver-kriska/claude-elixir-phoenix100MIT
oliver-kriska/claude-elixir-phoenix100MIT
irahardianto/awesome-agv100MIT

Migawka bazy z 13.11.2026 · wersja paczki 562ed9712528 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95elixir-otp-patterns
    Opisuje wzorce OTP w Elixirze (GenServer, Supervisor, Agent, Task) do budowy współbieżnych aplikacji odpornych na awarie.
  • 90elixir-code-review
    Przegląda kod Elixir pod kątem idiomatycznych wzorców, podstaw OTP i dokumentacji, w plikach .ex i .exs: dopasowanie wzorców, GenServer i dokumentacja modułów.
  • 100otp
    Projektuje i debuguje współbieżność Elixira, stan procesów i nadzór: GenServer, Supervisor, Task, Registry, ETS, wąskie gardła procesów i potoki Broadway.
  • 100elixir
    Wspiera programowanie w Elixirze: dopasowanie wzorców, GenServer, supervisory OTP i kanały Phoenix, dla współbieżnych, rozproszonych i odpornych na błędy systemów.
  • 100elixir
    Pomaga pisać i refaktoryzować Elixir i OTP na BEAM: GenServery, drzewa nadzoru i strategie restartu, dopasowanie wzorców, projekty mix oraz diagnozę pętli restartów i rosnącej skrzynki.
  • 90elixir-pro
    Pisze idiomatyczny kod w Elixirze z wzorcami OTP, drzewami nadzoru i Phoenix LiveView oraz pomaga w optymalizacji BEAM.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.