How to Find the Stinky Parts of Your Code (Part II)

How to Find the Stinky Parts of Your Code (Part II)

There are more code smells. Let’s keep changing the aromas. We see several symptoms and situations that make us doubt the quality of our development. Let's look at some possible solutions.

There are more code smells. Let’s keep changing the aromas. We see several symptoms and situations that make us doubt the quality of our development. Let's look at some possible solutions.

Most of these smells are just hints of something that might be wrong. They are not rigid rules.

This is part II. Part I can be found here.

Code Smell 06 - Too Clever Programmer

The code is difficult to read, there are tricky with names without semantics. Sometimes using language's accidental complexity.

Image Source: [NeONBRAND_](https://unsplash.com/@neonbrand?ref=hackernoon.com) on [Unsplash_](https://unsplash.com/s/photos/smart-brain?ref=hackernoon.com)

Problems

  • Readability
  • Maintainability
  • Code Quality
  • Premature Optimization

Solutions

  1. Refactor the code
  2. Use better names

Examples

  • Optimized loops

Exceptions

  • Optimized code for low-level operations.

Sample Code

Wrong

function primeFactors(n){
      var f = [],  i = 0, d = 2;  

      for (i = 0; n >= 2; ) {
         if(n % d == 0){
           f[i++]=(d); 
           n /= d;
        }
        else{
          d++;
        }     
      }
      return f;
    }

Right

function primeFactors(numberToFactor){
      var factors = [], 
          divisor = 2,
          remainder = numberToFactor;

      while(remainder>=2){
        if(remainder % divisor === 0){
           factors.push(divisor); 
           remainder = remainder/ divisor;
        }
        else{
          divisor++;
        }     
      }
      return factors;
    }

Detection

Automatic detection is possible in some languages. Watch some warnings related to complexity, bad names, post increment variables, etc.

pixel-face code-smells clean-code stinky-code-parts refactor-legacy-code refactoring stinky-code common-code-smells

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Find the Stinky Parts of Your Code (Part I)

The code smells bad. Let’s see how to change the aromas. In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most of these smells are just hints of something that might be wrong. They are not rigid rules.

4 Wheel Parts Coupon Code Military Offers To Save 50% Off

Avail 50% off on SUV, 4X4 vehicles spare parts & accessories by using 4 wheel parts coupon code military through The Extra Discount.

Static Code Analysis: What It Is? How to Use It?

Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.

Code Trashing Symptom

There are a set of skills and qualities which make the ideal software developer we are all searching to be or searching for to employ. However, right now I am going to emphasize the importance of a quality that is mostly found in senior developers.

Common Code Smells in Data Science Projects and How to Fix Them

Common Code Smells in Data Science Projects and How to Fix Them - A lot of data science and ML projects I’ve worked with are written by people who are not coders first. Their primary concern is a working…