ed3dai/ed3d-plugins/howto-functional-vs-imperative
Claude Code and agent skill by ed3dai/ed3d-plugins
- community
Checking that the SKILL.md file is still in the repository.
Use when writing or refactoring code, before creating files - enforces separation of pure business logic (Functional Core) from side effects (Imperative Shell) using FCIS pattern with mandatory file classification
Install
npx vskill@latest install ed3dai/ed3d-plugins/howto-functional-vs-imperativeSKILL.md
Functional Core, Imperative Shell (FCIS)
Overview
Core principle: Separate pure business logic (Functional Core) from side effects (Imperative Shell). Pure functions go in one file, I/O operations in another.
Why this matters: Pure functions are trivial to test (no mocks needed). I/O code is isolated to thin shells. Bugs become structurally impossible when business logic has no side effects.
When to Use
Use FCIS when:
- Writing any new code file
- Refactoring existing code
- Reviewing code for architectural decisions
- Deciding where logic belongs
Trigger symptoms:
- "Where should this function go?"
- Creating a new file
- Adding database calls to logic
- Adding file I/O to calculations
- Writing tests that need complex mocking
MANDATORY: File Classification
YOU MUST add pattern comment to every file containing runtime behavior:
If file genuinely cannot be separated (rare), document why:
No file with runtime behavior without classification. If you create a file that contains functions, classes with methods, or orchestration logic without this comment, you have violated the requirement.
Exempt: Files Without Runtime Behavior
DO NOT add pattern comments to:
- Type-only files - files exporting only types, interfaces, or type aliases (no runtime code)
- Constants/enum-like files - static data declarations, no functions
- Barrel/index files - re-exports only (
export * from './foo') - Test files - tests exercise core/shell code but aren't themselves core or shell
- Generated files - machine-generated code
- Bash/shell scripts (.sh, .bash) - inherently imperative
- Configuration files (eslint.config.js, tsconfig.json, .env, etc.)
- Markdown documentation (.md)
- HTML files (.html)
- Task runner files (justfile, Makefile, etc.)
- Package manifests (package.json, pyproject.toml, etc.)
- Data files (JSON, YAML, CSV, etc.)
Note: If an exempt file grows to include runtime logic (e.g., a "types" file gains helper functions, or a constants file gains factory functions), it crosses the threshold and MUST be classified.
Classification applies to application source files containing runtime behavior (functions with logic, classes with methods, I/O orchestration).
File Type Definitions
Functional Core Files
Contains ONLY:
- Pure functions (same input -> same output, always)
- Business logic, validations, calculations, transformations
- Data structure operations
- Logging (EXCEPTION: loggers are permitted in Functional Core)
NEVER contains:
- File I/O (reading, writing files)
- Database operations (queries, updates, connections)
- HTTP requests or responses
- Environment variable access
- Date.now(), Math.random(), or other non-deterministic functions
- State mutations outside function scope
Logging exception: Functions MAY accept and use loggers. For unit tests, pass no-op loggers. This is the ONLY permitted side effect in Functional Core.
Test signature: Simple assertions, no mocks except logger (if used).
Imperative Shell Files
Contains ONLY:
- I/O operations: file system, database, HTTP, environment
- Orchestration: gather data -> call Functional Core -> persist results
- Error handling for I/O failures
- Minimal business logic (coordination only)
NEVER contains:
- Complex calculations
- Business rule validations
- Data transformations beyond format conversion
Test signature: Integration tests with real dependencies or test doubles.
Code Flow Pattern
Every operation follows this sequence. No exceptions.
Decision Framework
Before writing a function, ask:
Questions to ask:
- Can this logic run without file system, database, network, or environment?
- YES -> Functional Core
- NO -> Does it coordinate I/O or contain business logic?
- I/O coordination -> Imperative Shell
- Business logic + I/O -> STOP. Refactor or escalate to user.
Common Mistakes and Rationalizations
| Excuse/Thought Pattern | Reality | What To Do | |
|---|---|---|---|
| "Just one file read in this calculation" | File I/O = side effect. Not Functional Core. | Extract to Shell. Pass data as parameter. | |
| "Database is passed as parameter, so it's pure" | Database operations are I/O. Not pure. | Move to Shell. Core receives data, not DB connection. | |
| "This validation needs to check if file exists" | File system check = I/O. Not Functional Core. | Shell checks file, passes boolean to Core validation. | |
| "Small HTTP call, won't hurt" | HTTP = side effect. Breaks purity guarantee. | Shell makes request, Core processes response data. | |
| "Need Date.now() for timestamp calculation" | Non-deterministic. Not pure. | Shell passes timestamp as parameter. | |
| "Logging is a side effect, should remove" | WRONG. Logging is explicitly permitted. | Keep logger. This is the exception. | |
| "This function does both logic and I/O, but it's simpler" | Mixed concerns = untestable without mocks. | Split into Core (logic) + Shell (I/O). Test Core simply. | |
| "File classification is overhead" | Prevents entire classes of bugs. Non-negotiable. | Add classification comment. Takes 10 seconds. | |
| "I'll refactor later" | Later never comes. Do it now. | Classify and separate now. | |
| "Performance requires mixing" | Prove it with benchmarks. Usually wrong. | Separate first. Optimize with evidence. Mark Mixed (unavoidable) with justification. |
Red Flags - STOP and Refactor
If you catch yourself doing ANY of these, STOP:
- File I/O in a "pure" function (open, read, write, exists checks)
- Database passed as parameter to Functional Core (queries, updates, connections)
- HTTP requests in business logic (fetch, axios, requests)
- Environment variables in calculations (process.env, os.getenv)
- Math.random() or Date.now() in Functional Core (non-deterministic)
- Creating a file with runtime behavior without pattern classification comment
- Thinking "just this once" about mixing concerns
All of these mean: Extract I/O to Shell. Pass data to Core. Classify file correctly.
Implementation Patterns
Functional Core Pattern
No I/O. No database. No file system. Only computation.
Imperative Shell Pattern
Shell is thin. Core does heavy lifting. Testable separately.
Mixed (Needs Refactoring) - Bad Example
Testing this requires database mocks. Fragile. Refactor using patterns above.
Logger Exception Details
Loggers are EXPLICITLY PERMITTED in Functional Core.
For unit tests: Pass no-op logger or None. Function remains pure for testing.
Refactoring Patterns
Common patterns for separating concerns:
Extract Pure Core from Impure Functions
Symptom: Function mixes I/O with logic
Return Values Instead of Mutating
Symptom: Methods mutate in place, making before/after comparison hard
Add Missing Inverse Operations
Symptom: One-way operation exists but no inverse for testing roundtrips
Replace Hardcoded Dependencies
Symptom: Functions use globals or hardcoded config, can't test edge cases
Refactoring Priority
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/ed3d-house-style/skills/howto-functional-vs-imperative/SKILL.md
Popularity
- Repository stars
- 249
- Repository forks
- 32
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ed3dai/ed3d-plugins/howto-functional-vs-imperative)