clean-code
Refactoring patterns, SOLID principles, code smell detection, and pragmatic coding standards.
What this skill does
# Clean Code
Pragmatic refactoring patterns and coding standards. Not dogma — practical improvements.
## Code Smells to Fix
### Long functions (>30 lines)
Extract into named functions. The name documents intent better than a comment.
### Deep nesting (>3 levels)
Use early returns, guard clauses, or extract helper functions.
```javascript
// Bad
function process(user) {
if (user) {
if (user.active) {
if (user.verified) {
// actual logic
}
}
}
}
// Good
function process(user) {
if (!user) return;
if (!user.active) return;
if (!user.verified) return;
// actual logic
}
```
### Magic numbers/strings
Extract to named constants.
### Duplicate code
If you copy-paste 3+ times, extract. Two occurrences are often fine.
### Dead code
Delete it. Git has history if you need it back.
## SOLID Principles (Practical Version)
- **Single Responsibility** — A function does one thing. A module handles one concern. If you can't name it simply, it does too much.
- **Open/Closed** — Extend with new code, don't modify working code. Use composition, interfaces, or strategy patterns.
- **Liskov Substitution** — Subtypes must work where parent types are expected. Don't override methods to throw "not implemented."
- **Interface Segregation** — Don't force clients to depend on methods they don't use. Smaller interfaces > fat interfaces.
- **Dependency Inversion** — Depend on abstractions, not concrete implementations. Pass dependencies in, don't create them inside.
## Refactoring Techniques
### Extract Function
```bash
# Find long functions
grep -rn "function\|=>\|def " src/ | awk -F: '{print $1}' | sort | uniq -c | sort -rn | head -10
```
### Rename for clarity
```bash
# Find vague variable names
grep -rn "\bdata\b\|\btemp\b\|\bresult\b\|\binfo\b\|\bstuff\b" src/ --include="*.ts" --include="*.py" | head -20
```
### Remove dead code
```bash
# Find unused exports (TypeScript)
npx ts-unused-exports tsconfig.json
# Find unused functions (crude)
grep -rn "function " src/ --include="*.ts" -l | while read f; do
grep -oP "function \K\w+" "$f" | while read fn; do
count=$(grep -rn "\b$fn\b" src/ --include="*.ts" | wc -l)
[ "$count" -le 1 ] && echo "Possibly unused: $fn in $f"
done
done
```
### Simplify conditionals
Replace nested if/else with:
- Early returns
- Lookup tables/maps
- Polymorphism (if the condition is on type)
## Naming Conventions
- Functions: verb + noun (`getUser`, `validateEmail`, `parseResponse`)
- Booleans: `is`/`has`/`should` prefix (`isActive`, `hasPermission`)
- Collections: plural (`users`, `orderItems`)
- Avoid: `handle`, `process`, `manage` without specificity — they say nothing
## Notes
- Refactor in small, tested steps. Don't rewrite a whole file in one commit.
- Pragmatism over purity. Three similar lines are better than a premature abstraction.
- The best code needs no comments. But when logic isn't obvious, explain *why*, not *what*.
- Run tests after each refactoring step. If tests break, you changed behavior, not just structure.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.