code-philosophy

Applies five defensive coding laws to internal logic and data flow design.

1|Updated Jul 23, 2026
One-click install
npx skills add https://github.com/sanjanb/my-agent-harness --skill code-philosophy-sanjanb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-philosophy
Source: https://github.com/sanjanb/my-agent-harness/tree/main/skills/code-philosophy
Command: npx skills add https://github.com/sanjanb/my-agent-harness --skill code-philosophy-sanjanb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate complexity through deep nesting, repeated validation, hidden mutations, and silent failures. This Skill provides a consistent philosophy for writing internal logic so that data flows naturally and invalid states become impossible. ## Core Features & Use Cases - The 5 Laws of Elegant Defense: Guard clauses, parse-don't-validate, atomic predictability, fail-fast behavior, and intentional naming. - Broad Applicability: Applies to backend services, React components, hooks, state management, and any code where functionality matters. - Adherence Checklist: A five-point verification list to run before completing any coding task. - Use Case: When refactoring a tangled function with nested conditionals, apply the Law of the Early Exit to flatten the logic and the Parse-Don't-Validate law to move type checks to the boundary. ## Quick Start Review this function using the 5 Laws of Elegant Defense and refactor it to use guard clauses and fail-fast error handling.

Frequently Asked Questions about code-philosophy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce nesting in my functions?

Use guard clauses following the Law of the Early Exit. Handle edge cases, nulls, and errors at the top of the function with early returns, so the main logic stays flat instead of wrapping work inside deep if blocks.

What does parse don't validate mean in practice?

Parse don't validate means converting raw input into trusted, typed data at the system boundary instead of re-checking it throughout the code. Once data enters internal logic, no defensive checks are needed, keeping core algorithms clean.

Does this philosophy apply to React components and hooks?

Yes, the 5 Laws apply to React components, hooks, and state management as well as backend code. Guard clauses handle loading and error states early, and pure functions keep rendering predictable.

Why should code fail fast instead of handling bad data?

Fail fast means halting immediately with a descriptive error when a state is invalid, rather than patching bad data. Silent failures create complexity downstream because later code must account for half-broken states.

When should I not use pure functions?

Pure functions are preferred where possible, but side effects like network calls, logging, and persistence are unavoidable. The philosophy asks you to isolate those effects at boundaries and keep core logic pure and predictable.