<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rami TRABELSI on Medium]]></title>
        <description><![CDATA[Stories by Rami TRABELSI on Medium]]></description>
        <link>https://medium.com/@trabelsi.med.rami?source=rss-59f29c2ff1a2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SEGK_YxQG698LBdM6TdRCA.png</url>
            <title>Stories by Rami TRABELSI on Medium</title>
            <link>https://medium.com/@trabelsi.med.rami?source=rss-59f29c2ff1a2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 11:31:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@trabelsi.med.rami/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[5 Code Smells That Are Hurting Your Code Quality]]></title>
            <link>https://medium.com/@trabelsi.med.rami/5-code-smells-that-are-hurting-your-code-quality-2f29ed1401fb?source=rss-59f29c2ff1a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f29ed1401fb</guid>
            <category><![CDATA[maintainability]]></category>
            <category><![CDATA[code-smells]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[code-quality]]></category>
            <dc:creator><![CDATA[Rami TRABELSI]]></dc:creator>
            <pubDate>Sun, 25 Aug 2024 16:10:56 GMT</pubDate>
            <atom:updated>2024-08-25T16:13:31.382Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zfYBAA96bTnQhrHhGAdhQQ.jpeg" /></figure><p>In software development, some problems don’t scream at you — they subtly hint that something isn’t quite right. These subtle issues are what we call <strong>code smells</strong>. They don’t crash your code or cause immediate bugs, but they do signal that your code might be heading in a troublesome direction.</p><p><strong>So, What Exactly Is a Code Smell?</strong></p><p>A code smell is a hint that there might be a deeper issue with your code’s structure or design. It’s not necessarily something that will cause your program to fail, but more like a whisper that your code could be better. It’s the kind of thing that, if left unattended, can lead to more complex problems as your project grows.</p><p><strong>Why Should You Care About Code Smells?</strong></p><p>As your project scales, so does the complexity of your codebase. Ignoring code smells is like ignoring a leaky faucet — it might seem harmless now, but over time it can cause significant damage. Addressing code smells early helps keep your codebase clean, maintainable, and ready for future changes.</p><h3><strong>Common Code Smells and How to Deal with Them</strong></h3><p>Let’s dive into some of the most common code smells you might encounter, along with examples and how to handle them:</p><h3>1. <strong>Duplicated Code:</strong></h3><p>• <strong>What It Is:</strong> Repeating the same code in multiple places.</p><p>• <strong>Why It’s a Problem:</strong> When you copy-paste code, you’re setting yourself up for maintenance headaches. Any change needs to be made in several places, increasing the risk of errors.</p><p>• <strong>Example:</strong></p><pre>fun calculateRectangleArea(width: Double, height: Double): Double {<br>    return width * height<br>}<br><br>fun calculateTriangleArea(base: Double, height: Double): Double {<br>    return 0.5 * base * height<br>}</pre><ul><li><strong>How to Fix It:</strong> Extract the common code into a reusable function or method.</li></ul><pre>fun calculateArea(factor: Double, dimension1: Double, dimension2: Double): Double {<br>    return factor * dimension1 * dimension2<br>}<br><br>fun calculateRectangleArea(width: Double, height: Double): Double {<br>    return calculateArea(1.0, width, height)<br>}<br><br>fun calculateTriangleArea(base: Double, height: Double): Double {<br>    return calculateArea(0.5, base, height)<br>}</pre><h3>2. <strong>Long Method:</strong></h3><p>• <strong>What It Is:</strong> A method that tries to do too much or is just too lengthy.</p><p>• <strong>Why It’s a Problem:</strong> Long methods are harder to understand, test, and maintain. They often violate the Single Responsibility Principle (SRP), meaning they’re handling more than one responsibility.</p><ul><li><strong>Example:</strong></li></ul><pre>fun processOrder(order: Order) {<br>    validateOrder(order)<br>    calculateTotal(order)<br>    applyDiscount(order)<br>    processPayment(order)<br>    sendConfirmationEmail(order)<br>}</pre><ul><li><strong>How to Fix It:</strong> Break the method into smaller, more focused methods that each do one thing well.</li></ul><pre>fun processOrder(order: Order) {<br>    validateOrder(order)<br>    calculateTotalAndApplyDiscount(order)<br>    finalizeOrder(order)<br>}<br><br>fun calculateTotalAndApplyDiscount(order: Order) {<br>    calculateTotal(order)<br>    applyDiscount(order)<br>}<br><br>fun finalizeOrder(order: Order) {<br>    processPayment(order)<br>    sendConfirmationEmail(order)<br>}</pre><h3>3. <strong>Large Class:</strong></h3><p>• <strong>What It Is:</strong> A class packed with too much functionality.</p><p>• <strong>Why It’s a Problem:</strong> Large classes are tough to manage and make your code harder to navigate. They usually indicate that the class is handling too many responsibilities.</p><ul><li><strong>Example:</strong></li></ul><pre>class OrderProcessor {<br>    fun validateOrder(order: Order) { /* ... */ }<br>    fun calculateTotal(order: Order) { /* ... */ }<br>    fun applyDiscount(order: Order) { /* ... */ }<br>    fun processPayment(order: Order) { /* ... */ }<br>    fun sendConfirmationEmail(order: Order) { /* ... */ }<br>    fun generateInvoice(order: Order) { /* ... */ }<br>}</pre><ul><li><strong>How to Fix It:</strong> Refactor the class into smaller, more specialized classes, each focused on a single responsibility.</li></ul><pre>class OrderValidator {<br>    fun validate(order: Order) { /* ... */ }<br>}<br><br>class OrderCalculator {<br>    fun calculateTotal(order: Order) { /* ... */ }<br>    fun applyDiscount(order: Order) { /* ... */ }<br>}<br><br>class PaymentProcessor {<br>    fun processPayment(order: Order) { /* ... */ }<br>}<br><br>class EmailService {<br>    fun sendConfirmation(order: Order) { /* ... */ }<br>}<br><br>class InvoiceGenerator {<br>    fun generateInvoice(order: Order) { /* ... */ }<br>}</pre><h3>4. <strong>God Object:</strong></h3><p>• <strong>What It Is:</strong> A class that knows too much or does too much.</p><p>• <strong>Why It’s a Problem:</strong> This creates tight coupling, making your code fragile and difficult to modify without breaking something else.</p><ul><li><strong>Example:</strong></li></ul><pre>class ApplicationManager {<br>    fun start() { /* ... */ }<br>    fun stop() { /* ... */ }<br>    fun loadConfiguration() { /* ... */ }<br>    fun saveData() { /* ... */ }<br>    fun renderUI() { /* ... */ }<br>}</pre><ul><li><strong>How to Fix It:</strong> Distribute the responsibilities of the God object among smaller, more focused classes.</li></ul><pre>class ConfigurationManager {<br>    fun loadConfiguration() { /* ... */ }<br>}<br><br>class DataManager {<br>    fun saveData() { /* ... */ }<br>}<br><br>class UIManager {<br>    fun renderUI() { /* ... */ }<br>}<br><br>class ApplicationManager(<br>    private val configManager: ConfigurationManager,<br>    private val dataManager: DataManager,<br>    private val uiManager: UIManager<br>) {<br>    fun start() { /* ... */ }<br>    fun stop() { /* ... */ }<br>}</pre><h3>5. <strong>Switch Statements:</strong></h3><p>• <strong>What It Is:</strong> Overuse of switch or if-else statements, particularly for deciding behavior.</p><p>• <strong>Why It’s a Problem:</strong> These statements can lead to code duplication and make your code harder to extend. They often indicate a need for polymorphism.</p><ul><li><strong>Example:</strong></li></ul><pre>fun calculateDiscount(customerType: String): Double {<br>    return when (customerType) {<br>        &quot;Regular&quot; -&gt; 0.1<br>        &quot;VIP&quot; -&gt; 0.2<br>        &quot;Employee&quot; -&gt; 0.3<br>        else -&gt; 0.0<br>    }<br>}</pre><ul><li><strong>How to Fix It:</strong> Use polymorphism or strategy patterns to handle varying behavior instead of relying on switch statements.</li></ul><pre>interface DiscountStrategy {<br>    fun calculateDiscount(): Double<br>}<br><br>class RegularCustomer : DiscountStrategy {<br>    override fun calculateDiscount() = 0.1<br>}<br><br>class VIPCustomer : DiscountStrategy {<br>    override fun calculateDiscount() = 0.2<br>}<br><br>class Employee : DiscountStrategy {<br>    override fun calculateDiscount() = 0.3<br>}<br><br>fun calculateDiscount(strategy: DiscountStrategy): Double {<br>    return strategy.calculateDiscount()<br>}</pre><p>—</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*gH3VXtG__ddRbOh4bFK4Yw.jpeg" /></figure><p><strong>Wrapping Up: Keep Your Code Smell-Free</strong></p><p>Code smells are like the early warning signs of deeper issues in your code. They don’t always cause immediate problems, but they’re worth paying attention to. By addressing them through refactoring, you can keep your codebase in top shape — clean, maintainable, and ready for whatever comes next.</p><p>Remember, good code is not just about making it work. It’s about making it work well, today and in the future. So, keep an eye out for those code smells, and don’t hesitate to clean them up.</p><blockquote><em>“Clean code always looks like it was written by someone who cares.”</em></blockquote><blockquote>— Robert C. Martin (Uncle Bob)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f29ed1401fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>