defensive-programming

Enforce immutability, strict visibility, and contract-based validation across codebases.

22|6|Updated Feb 11, 2026
One-click install
npx skills add https://github.com/yuchenzhu-research/zhihu-scraper --skill defensive-programming
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: defensive-programming
Source: https://github.com/yuchenzhu-research/zhihu-scraper/tree/main/references/skills/engineering/engineering-progression/defensive-programming
Command: npx skills add https://github.com/yuchenzhu-research/zhihu-scraper --skill defensive-programming

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Defensive programming patterns help reduce misuse and bugs by enforcing immutability, strict visibility, and contract-based validation across codebases.

Core Features & Use Cases

  • Immutability by default across variables, fields, and parameters
  • Minimal visibility and sealed types to guard API surfaces
  • Design by contract with preconditions, postconditions, and invariants
  • Boundary validation and safe data handling
  • Resource safety (RAII) and deterministic cleanup
  • Safe defaults, exhaustive matching, and explicit error handling

Quick Start

Adopt defensive programming principles in your module by applying immutable defaults and sealed public APIs from the outset.

Frequently Asked Questions about defensive-programming

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

FAQPage Schema
How do I enforce immutability and strict visibility to write safer code?

Defensive programming principles enforce immutability and minimal visibility by applying sealed types and boundary validation across your codebase, reducing API misuse and bugs by default.

What is boundary validation and how does it improve API reliability?

Boundary validation is a defensive programming pattern that applies contract-based preconditions, postconditions, and invariants at API edges to ensure safe data handling and improve overall reliability.

How do I implement design by contract for preconditions and postconditions?

Implement design by contract by applying defensive programming patterns that enforce preconditions, postconditions, and invariants across your codebase to strictly guard module boundaries and ensure robust API behavior.

Does defensive programming work for resource safety and deterministic cleanup?

Yes, defensive programming addresses resource safety by applying deterministic cleanup patterns like RAII, ensuring safe defaults and explicit error handling to provide robust resource management across libraries and services.

When should I use sealed types and exhaustive matching in my codebase?

Use sealed types and exhaustive matching when designing public APIs to guard surfaces, minimize visibility, and enforce explicit error handling, preventing unhandled cases and reducing misuse across your codebase.

What are the limitations of defensive copies for safe data handling?

Defensive copies protect boundary integrity but may introduce overhead; defensive programming balances this by enforcing strict validation and immutability by default to ensure safe data handling without excessive duplication.