Codigo Limpo Epub Here

</body> </html>

<h3>Switch statements: hide them</h3> <p>Use polymorphism or a factory. A <code>switch</code> with multiple cases usually violates the Single Responsibility Principle.</p>

<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> codigo limpo epub

<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>

<h2>5. Objects and Data Structures</h2> <p>Objects hide data behind abstractions. Data structures expose data and have no meaningful functions.</p> Follow the &lt;strong&gt;F

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

<h2>4. Formatting: Vertical Density and Horizontal Flow</h2> <p>Code formatting is communication. Use consistent rules.</p> Formatting: Vertical Density and Horizontal Flow&lt

<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>

<ul> <li><strong>Rigidity</strong>: A small change breaks many parts → increase cohesion, reduce coupling.</li> <li><strong>Fragility</strong>: Changes cause unexpected failures → add tests, encapsulation.</li> <li><strong>Opacity</strong>: Code is hard to understand → rename, refactor, add explanatory variables.</li> <li><strong>Feature envy</strong>: A method seems more interested in another class’s data → move the method.</li> <li><strong>Long parameter list</strong>: Wrap parameters into an object (DTO).</li> </ul>

<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>