refactor

Refactor ADVPL/TLPP code with behavior-preserving, small-step changes.

115|54|Updated May 25, 2026
One-click install
npx skills add https://github.com/totvs/engpro-advpl-tlpp-skills --skill refactor-totvs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/totvs/engpro-advpl-tlpp-skills/tree/main/skills/advpl-tlpp/refactor
Command: npx skills add https://github.com/totvs/engpro-advpl-tlpp-skills --skill refactor-totvs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you refactor messy or hard-to-maintain ADVPL/TLPP code by improving structure, readability, and maintainability while preserving existing behavior.

Core Features & Use Cases

  • Surgical, behavior-preserving refactoring: targets maintainability issues without “rewriting from scratch.”
  • Smell-driven cleanup: addresses common problems like long functions, duplication, magic values, nested conditionals, and dead code.
  • AdvPL/TLPP-specific guardrails: applies ecosystem rules such as using proper file extensions for TLPP features, replacing legacy error handling patterns, and improving scope safety (Private→Local).
  • Practical refactoring workflow: emphasizes small steps, commits, and testing/verification after each change.

Quick Start

Use the refactor skill to clean up the provided ADVPL/TLPP routine by extracting functions, reducing complexity, and renaming for clarity while keeping behavior identical to the original.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor ADVPL code to improve maintainability without changing its behavior?

To refactor ADVPL code safely, apply a small-step, behavior-preserving process that extracts functions, reduces complexity, and renames variables while keeping the original output identical. Verify functionality with tests after each change.

What is the best way to clean up long functions and duplicated logic in TLPP?

Cleaning up long functions and duplicated logic in TLPP involves smell-driven refactoring: extract reusable functions, tighten variable scope from Private to Local, and apply TLPP typing to improve clarity without altering execution.

Can I modernize legacy error handling in ADVPL by replacing it with TLPP try-catch?

Yes, modernizing legacy ADVPL error handling involves replacing old patterns with TLPP try-catch structures. This refactoring step improves scope safety and error management while strictly preserving the original application behavior.

Does refactoring ADVPL code require rewriting the entire routine from scratch?

No, surgical refactoring targets specific maintainability issues like nested conditionals and magic values without rewriting from scratch. It uses a checklist-based cleanup plan to ensure structure improves safely in small, verifiable steps.

Why should I tighten variable scope from Private to Local when refactoring ADVPL?

Tightening variable scope from Private to Local during ADVPL refactoring prevents unintended side effects and improves code safety. This ecosystem-specific guardrail enhances readability and maintainability without changing the functional behavior.