Elixir Antipatterns
Core catalog of 8 critical Elixir/Phoenix anti-patterns covering error handling...
Install
npx skills add Gentleman-Programming/Gentleman-Skills --skill elixir-antipatterns -g -a claude-code -y- Repository
- Gentleman-Programming/Gentleman-Skills661
- Category
- Testing
- Updated
- 7mo ago
- License
- MIT
- Context cost
- Mediumabout 2,028 tokens
- Runs scripts
- No, instructions only
What it does
Core catalog of 8 critical Elixir/Phoenix anti-patterns covering error handling, separation of concerns, Ecto queries, and testing. Trigger: During Elixir code review, refactoring sessions, or when writing Phoenix/Ecto code.
Elixir Anti-Patterns
Critical anti-patterns that compromise robustness and maintainability in Elixir/Phoenix applications.
Complement with:
mix formatandCredofor style enforcement
Extended reference: SeeEXTENDED.mdfor 40+ patterns and deep-dive examples
When to Use
Topics: Error handling (3 patterns) • Architecture (2 patterns) • Performance (2 patterns) • Testing (1 pattern)
Load this skill when:
- Writing Elixir modules and functions
- Working with Phoenix Framework (Controllers, LiveView)
- Building Ecto schemas and database queries
- Implementing BEAM concurrency (Task, GenServer)
- Handling errors with tagged tuples
- Writing tests with ExUnit
Critical Patterns
Quick reference to the 8 core patterns this skill enforces:
- Tagged Tuples: Return
{:ok, value} | {:error, reason}instead ofnilor exceptions - Explicit @spec: Document error cases in function signatures
- Context Separation: Business logic in contexts, not LiveView
- Preload Associations: Use
Repo.preload/2to avoid N+1 queries - with Arrow Binding: Use
<-for all failable operations inwith - Database Indexes: Index frequently queried columns
- Test Assertions: Every test must assert expected behavior
- Cohesive Functions: Group
withchains >4 steps into functions
See
## Anti-Patternssection below for detailed ❌ BAD / ✅ CORRECT code examples.
Code Examples
Example 1: Error Handling with Tagged Tuples
# ✅ CORRECT - Errors as values, explicit in @spec
defmodule UserService do
@spec fetch_user(String.t()) :: {:ok, User.t()} | {:error, :not_found}
def fetch_user(id) do
case Repo.get(User, id) do
nil -> {:error, :not_found}
user -> {:ok, user}
end
end
end
# ❌ BAD - Exceptions for business errors
def fetch_user(id) do
Repo.get(User, id) || raise "User not found"
end


