Puy Web
Profile Blog
EN TH
Blog Code Smells & Code Refactoring
Code Smells & Code Refactoring
Coding Jun 15, 2019

Code Smells & Code Refactoring

Has anyone ever written code that ended up tangled like the messy ball of yarn on the left? Have you ever wondered why it gets so tangled, even when we often think we've designed it perfectly? So, what do we need to do to make our code look as neat and beautiful as the spool of thread on the right? In the upcoming articles, I'll be gradually writing more about this for you all to read, haha! ^^y

In this article, let's first get to know the root causes that turn our code into a tangled mess (Spaghetti Code). We collectively call these causes Code Smells—basically, something that seems a bit "off" and gives us a hint that our code is definitely going to cause problems down the line.

Once we catch a whiff of these peculiar smells, the solution is to do Code Refactoring. This makes our code highly manageable, beautiful, and much easier to read. Anyone who drops by and sees your code will be full of praise, haha!

Next, let's familiarize ourselves with the different categories of Code Smells:

  • Bloaters: Code, functions, or classes that just keep expanding as we write, eventually growing into giant monsters that we absolutely do not want to mess with.

  • Object-Orientation Abusers: Incomplete implementations or the incorrect application of Object-Oriented Programming (OOP) principles.

  • Change Preventers: The classic situation where modifying code in one place impacts several other places, forcing you to chase down and fix a chain reaction of errors.

  • Dispensables: Junk code or anything useless that doesn't add any real value to the program—whether that’s making the code look better, perform better, or simply making it easier to understand.

  • Couplers: Code that is overly dependent and tied together so tightly that it cannot be separated. This can apply to specific code blocks, functions, or entire classes.

Share this article:

Related Articles

Fix -bash: ng: command not found
Coding
Jul 15, 2019

Fix -bash: ng: command not found

When running any ng command, you might encounter the following error message: "ng: command not found".

Read More
gRPC with Spring Boot 101
Coding
Jul 10, 2019

gRPC with Spring Boot 101

gRPC is an RPC (Remote Procedure Call) framework originally developed by Google in 2015 and is now a part of the Cloud Native Computing Foundation (CNCF). It utilizes the HTTP/2 protocol, which is significantly faster than HTTP/1.1, and uses Protocol Buffers (Protobuf) as its Interface Definition Language (IDL) to compile the code needed for development.

Read More
FlutterBuilder
Coding
Jul 03, 2019

FlutterBuilder

Inside the Widget build(BuildContext context) function, you will notice that when rendering a Widget, we cannot directly use async / await or .then() from a Future and wait for the data to arrive before displaying it.

Read More
Code Smell Long Method Part 1
Coding
Jun 20, 2019

Code Smell Long Method Part 1

Long Method is one of the Code Smells in the Bloaters category. Its defining characteristic is having far too many lines of code. As a rule of thumb, any function or method exceeding 10 lines should be reviewed to see if it might cause tangled code in the future.

Read More