Delphi Clean Code

Apply clean-code rules to Delphi units for naming and memory management.

48|12|Updated Mar 20, 2026
One-click install
npx skills add https://github.com/delphicleancode/delphi-spec-kit --skill delphi-clean-code
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Delphi Clean Code
Source: https://github.com/delphicleancode/delphi-spec-kit/tree/main/.gemini/skills/clean-code
Command: npx skills add https://github.com/delphicleancode/delphi-spec-kit --skill delphi-clean-code

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Delphi projects often degenerate into hard-to-maintain spaghetti when guidelines are ignored. This Skill provides pragmatic rules to keep Delphi code readable, maintainable and robust.

Core Features & Use Cases

  • Single Responsibility Principle (SRP): A function or unit does ONE thing.
  • DRY & KISS: Avoid duplication and keep solutions simple.
  • Guard Clauses & Early Returns: Reduce nested conditionals and improve readability.
  • Naming Conventions: Consistent prefixes and verb-noun naming for clarity.
  • Memory Management Guidance: Use try/finally for objects and be deliberate with interfaces.
  • Anti-Patterns to Avoid: Identify and replace common pitfalls like God classes and overly long methods.

Quick Start

Refactor a sample Delphi unit to apply SRP, add guard clauses, and rename identifiers for clarity.

Frequently Asked Questions about Delphi Clean Code

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

FAQPage Schema
How do I refactor Delphi code to reduce nested conditionals and improve readability?

Refactor Delphi code by applying guard clauses and early returns to reduce nested conditionals. This approach flattens execution paths, making functions easier to read and maintain.

What are the best practices for memory management in Delphi to prevent leaks?

Delphi memory management best practices include using try/finally blocks for object lifecycles and being deliberate with interface references. This ensures objects are properly freed and reduces memory leak risks.

How do I apply the Single Responsibility Principle to existing Delphi units?

Apply the Single Responsibility Principle to Delphi units by ensuring each function or unit does exactly one thing. This reduces duplication and improves overall code maintainability.

Does this clean code approach work for large legacy Delphi projects?

Yes, this approach works across Delphi projects and units. It provides pragmatic rules to reduce duplication, improve naming, and enforce safer memory management and error handling in existing codebases.

What naming conventions should I use for Delphi identifiers?

Delphi naming conventions should use consistent prefixes and verb-noun naming for clarity. This ensures identifiers are predictable and self-documenting across the project.

How do I identify and replace common Delphi anti-patterns?

Identify Delphi anti-patterns like God classes and overly long methods, then replace them by applying DRY and KISS principles. This keeps solutions simple and avoids duplication.