Codigo Limpo Epub ✦ Original

<h2>7. Boundaries: Keep Third-Party Code at Arm’s Length</h2> <p>Wrap external APIs (libraries, frameworks) to isolate changes. Do not let a specific JSON library leak into your core domain.</p>

<h2>1. Meaningful Names</h2> <p>Names are the smallest building blocks of code clarity. Every variable, function, or class name should reveal intent.</p>

<h2>Introduction</h2> <p>Clean code is not a luxury—it's a necessity. Code is read far more often than it is written. This guide distills the core ideas from Robert C. Martin’s <em>Clean Code</em> and decades of collective experience into actionable rules. You will learn how to name variables, write functions, handle errors, and structure classes so that your code tells a story, not a puzzle.</p>

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Clean Code - A Solid Guide</title> <style> /* Reset & base typography for clean reading */ body { font-family: Georgia, "Times New Roman", Times, serif; line-height: 1.5; margin: 0; padding: 0; color: #1a1a1a; background-color: #fefefe; } h1, h2, h3 { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: normal; margin-top: 1.5em; margin-bottom: 0.5em; page-break-after: avoid; } h1 { font-size: 1.8em; text-align: center; margin-top: 2em; margin-bottom: 1em; border-bottom: 1px solid #ccc; padding-bottom: 0.3em; } h2 { font-size: 1.5em; border-left: 4px solid #2c6e2c; padding-left: 0.6em; } h3 { font-size: 1.3em; font-style: italic; color: #2c6e2c; } p, li, blockquote { text-align: justify; hyphens: auto; } code { font-family: "Courier New", Courier, monospace; background-color: #f5f5f5; padding: 0.2em 0.4em; border-radius: 3px; font-size: 0.9em; white-space: pre-wrap; } pre { background-color: #f5f5f5; padding: 1em; border-left: 4px solid #2c6e2c; overflow-x: auto; font-size: 0.85em; font-family: "Courier New", Courier, monospace; margin: 1.2em 0; border-radius: 0 6px 6px 0; } .bad, .good { padding: 0.8em; margin: 1em 0; border-radius: 6px; } .bad { background-color: #ffe6e6; border-left: 6px solid #c00; } .good { background-color: #e6ffe6; border-left: 6px solid #2c6e2c; } .bad:before { content: "❌ Avoid: "; font-weight: bold; color: #a00; } .good:before { content: "✅ Prefer: "; font-weight: bold; color: #2c6e2c; } .tip { background-color: #eef4ff; padding: 0.8em; margin: 1em 0; border-radius: 6px; border-left: 6px solid #1e6f9f; } .tip:before { content: "💡 Tip: "; font-weight: bold; color: #1e6f9f; } ul, ol { margin: 0.8em 0; padding-left: 1.5em; } li { margin: 0.3em 0; } hr { margin: 2em 0; border: none; border-top: 1px dotted #bbb; } .footer { margin-top: 3em; font-size: 0.8em; text-align: center; color: #777; border-top: 1px solid #ddd; padding-top: 1em; } @media (prefers-color-scheme: dark) { body { background-color: #1e1e1e; color: #e0e0e0; } code, pre { background-color: #2d2d2d; } .bad { background-color: #2a1a1a; } .good { background-color: #1a2a1a; } .tip { background-color: #1a2a3a; } } </style> </head> <body> <h1>Clean Code: A Solid Guide</h1> <p style="text-align: center; font-style: italic;">Practical principles for writing readable, maintainable, and honest software.</p> codigo limpo epub

<div class="bad"> <pre>try { deletePage(page); registry.deleteReference(page.name); } catch (Exception e) { logError(e); throw new RuntimeException(); }</pre> </div>

<h2>6. Error Handling: Separate Logic from Errors</h2> <p>Error handling is one thing. Your business logic is another. Don’t mix them.</p>

<div class="tip"> Use pronounceable names: <code>generationTimestamp</code> instead of <code>genTmStmp</code>. </div> &lt;h2&gt;7

<ul> <li><strong>Law of Demeter</strong>: Don’t chain deeply: <code>customer.getAddress().getCity().toString()</code> is fragile. Prefer <code>customer.getCityAsString()</code>.</li> <li><strong>Hybrids (half-object, half-structure)</strong>: Avoid adding business logic inside getters/setters. Getters should not perform complex calculations.</li> </ul>

<h2>8. Unit Tests: First-Class Citizens</h2> <p>Tests must be kept as clean as production code. Follow the <strong>F.I.R.S.T.</strong> principles:</p> <ul> <li><strong>Fast</strong>: Run in milliseconds.</li> <li><strong>Independent</strong>: No test depends on another.</li> <li><strong>Repeatable</strong>: Same result in any environment.</li> <li><strong>Self-validating</strong>: Boolean output (pass/fail).</li> <li><strong>Timely</strong>: Written just before the production code (TDD).</li> </ul>

<div class="good"> <pre>// Instead of using Gson directly everywhere: public interface JsonParser { <T> T fromJson(String json, Class<T> type); } // Implement with Gson, Jackson, or System.Text.Json later.</pre> </div> This guide distills the core ideas from Robert C

<h3>Rule 3: Make meaningful distinctions</h3> <div class="bad"> <code>getUserInfo()</code> and <code>getUserData()</code> — what’s the difference? </div> <div class="good"> <code>getUserProfile()</code> vs <code>getUserCredentials()</code> </div>

<h2>10. Code Smells and Heuristics (Quick Reference)</h2>

<h2>9. Concurrency: Keep It Simple</h2> <p>Concurrency adds complexity. Mitigate it:</p> <ul> <li>Keep synchronized sections small.</li> <li>Use immutable objects when possible.</li> <li>Document threading semantics.</li> <li>Test concurrency code aggressively with tools like ThreadSanitizer or JCStress.</li> </ul>

<ul> <li><strong>Vertical density</strong>: Related concepts should be close. Local variables at the top of a function, helper functions directly below the calling function.</li> <li><strong>Horizontal spacing</strong>: Use spaces around operators (<code>a + b</code>), not tabs or chaotic mixtures. One indentation level = 4 spaces.</li> <li><strong>Team rules</strong>: If you work in a team, agree on an automatic formatter (Prettier, Black, gofmt).</li> </ul>