Refactors ADVPL/TLPP code on TOTVS Protheus: extracts functions, simplifies conditionals, removes dead code, improves Hungarian notation naming. For long functions, duplication, complexity.
From advpl-specialistnpx claudepluginhub thalysjuvenal/advpl-specialist --plugin advpl-specialistThis skill uses the workspace's default tool permissions.
Provides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.
Patterns and rules for safe refactoring of ADVPL/TLPP code on TOTVS Protheus. Focuses on improving code structure without changing behavior.
Detect: Function body > 100 lines with identifiable logical blocks Action: Extract logical block into a new Static Function Rule: The extracted function must receive all needed data as parameters (no shared Private/Public)
Before:
User Function ProcessaPedido()
// ... 40 lines validating data ...
// ... 30 lines calculating totals ...
// ... 50 lines saving to database ...
Return
After:
User Function ProcessaPedido()
If !fValidaDados(cCodPed)
Return .F.
EndIf
nTotal := fCalculaTotais(cCodPed)
lOk := fGravaPedido(cCodPed, nTotal)
Return lOk
Static Function fValidaDados(cCodPed)
// 40 lines
Return lValido
Static Function fCalculaTotais(cCodPed)
// 30 lines
Return nTotal
Static Function fGravaPedido(cCodPed, nTotal)
// 50 lines
Return lOk
Detect: Nested If > 3 levels deep, or long If/ElseIf chains Action: Use early return, guard clauses, or Do Case
Before:
If lCondicao1
If lCondicao2
If lCondicao3
// codigo principal
EndIf
EndIf
EndIf
After:
If !lCondicao1
Return
EndIf
If !lCondicao2
Return
EndIf
If !lCondicao3
Return
EndIf
// codigo principal
Detect: Variables declared but never used, unreachable code after Return, commented-out blocks Action: Remove the dead code entirely Rule: Use Grep to verify the variable/function is not called from other files before removing
Detect: Variables without Hungarian notation, single-letter names (except loop counters), unclear names Action: Rename following Hungarian notation convention
| Type | Prefix | Example |
|---|---|---|
| Character | c | cNomeCli, cCodProd |
| Numeric | n | nValor, nQtde |
| Logical | l | lOk, lContinua |
| Date | d | dDataIni, dEmissao |
| Array | a | aDados, aItens |
| Object | o | oModel, oReport |
| Block | b | bBloco, bFiltro |
Detect: Two or more code blocks with >5 similar lines Action: Extract common logic into a shared function Rule: Only extract if the logic is truly identical, not just visually similar
Detect: Functions with >5 parameters Action: Group related parameters into a JSON object or array Rule: Only apply if parameters are logically related