agentsclimarketplace

Clean code

Skill delphicleancode/delphi-spec-kit/.gemini/skills/clean-code

An opinionated ecosystem of rules, skills, and steerings to elevate Delphi development to a state-of-the-art level with Artificial Intelligence.

Install
npx -y skills add delphicleancode/delphi-spec-kit --skill clean-code

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Pragmatic clean code standards for Delphi — concise, direct, no over-engineering

SKILL.md

4.3 KB, as published. Nobody here has run it

Delphi Clean Code — Skill

CRITICAL SKILL — Be concise, direct and solution-focused.

Fundamental Principles

PrincipleRule
SRPA function/class does ONE thing
DRYDon't repeat code — extract and reuse
KISSSimplest solution that works
YAGNIDon't build what wasn't asked for
Boy ScoutLeave the code better than you found it

Naming Rules (Pascal Guide)

ElementConvention
VariablesReveal intent: LCustomerCount not N
MethodsVerb + noun: GetCustomerById not Customer
BooleansQuestion form: IsActive, HasPermission, CanEdit
ConstantsSCREAMING_SNAKE: MAX_RETRY_COUNT
FieldsPrefix F: FCustomerName
ParametersPrefix A: ACustomerName
Var. locationsPrefix L: LCustomer

Rule: If you need a comment to explain a name, rename it.

Method Rules

RuleDescription
ShortMaximum 20 lines, ideal 5-10
One ThingDo one thing and do it well
One LevelOne level of abstraction per method
Few ArgsMaximum 3 arguments, prefer 0-2
No Side EffectsDon't mute inputs unexpectedly

Code Structure

StandardApplication
Guard ClausesEarly returns for edge cases
Flat > NestedAvoid deep nesting (max 2 levels)
CompositionSmall compound methods
ColocationRelated code together

Guard Clauses in Delphi

// ❌ RUIM — nesting excessivo
procedure ProcessOrder(AOrder: TOrder);
begin
  if Assigned(AOrder) then
  begin
    if AOrder.Items.Count > 0 then
    begin
      if AOrder.IsValid then
      begin
        // logic real aqui
      end;
    end;
  end;
end;

// ✅ BOM — guard clauses
procedure ProcessOrder(AOrder: TOrder);
begin
  if not Assigned(AOrder) then
    raise EArgumentNilException.Create('AOrder cannot be nil');
  if AOrder.Items.Count = 0 then
    raise EBusinessRuleException.Create('Order must have items');
  if not AOrder.IsValid then
    raise EValidationException.Create('Order validation failed');

  // logic real aqui — sem nesting
end;

Anti-Patterns (DO NOT DO)

❌ Pattern✅ Fix
Comment each lineDelete obvious comments
Method > 20 linesShare by responsibility
Magic numbersNamed constants
with statementExplicit local variables
Global variablesConstructor injection
Generic CatchSpecific exceptions
Logic in OnClickDelegate to Service
God class / God unityOne class = one responsibility
Ignore Freetry/finally always

Memory Management

// ✅ Objetos temporários — sempre try/finally
LList := TStringList.Create;
try
  LList.Add('item');
  // usar LList
finally
  LList.Free;
end;

// ✅ Interfaces — reference counting automático
var LService: IMyService;
LService := TMyService.Create; // liberado automaticamente

// ✅ Owner pattern para componentes visuais
LButton := TButton.Create(Self); // Self libera automaticamente

AI Code Style

SituationAction
User requests featureWrite directly
User reports bugCorrect, don't explain
Requirement unclearAsk, don't assume

🔴 Before Editing (THINK FIRST!)

QuestionWhy
Which units use this?They can break
What does this unit matter?Interfaces can change
What tests cover this?Tests may fail
Is it a shared component?Multiple points affected

🔴 Rule: Edit the file + all dependents in the SAME task.

🔴 Self-Check (MANDATORY)

CheckPergunta
Goal achieved?Did I do exactly what was asked?
Edited files?Have I modified everything necessary?
Does the code work?Have I tested/verified?
No errors?Compiles without warnings?
Nothing forgotten?Edge cases treated?
Memory safe?Objects released correctly?

🔴 Rule: If ANY check fails, correct it before finishing.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.