Clean Code

9tTP...RxGQ
9 Jan 2024
22

A few years ago, many programs written were plagued with numerous issues in terms of code quality. The "spaghetti" logic brought about by unplanned coding, tons of duplication, postponed or omitted tests, and many other reasons led to the creation of complex, messy, and hard-to-maintain code, now commonly referred to as "bad code." In contemporary programming, with the widespread adoption of the "clean code" concept, conscious efforts and developed techniques have been directed towards improving code quality. As a result, the code written today tends to be cleaner, more organized, and simpler. However, as in any industry, there are still some shortcomings or instances of reluctance, leading to the production of subpar work in the software sector. What are the factors that contribute to writing bad code?

  1. Low expectations: There is a belief that the work will be subpar, particularly among university students or recent graduates with insufficient experience and expertise. While these reasons may be valid, having low expectations from an employee can lead to a lack of motivation and often results in outcomes worse than what could be achieved.
  2. Time constraints and rush to deliver: The stress caused by the rush to deliver can result in poor quality work. Writing code that adheres to clean code principles takes a back seat, and such hastily written code often introduces numerous errors (bugs).
  3. Working long hours: Both working under tight deadlines and working long hours negatively impact productivity.
  4. Striving for perfect code: Trying to write perfect code, including the existence of "God objects" – classes that do too much – can also be considered as deviating from clean code principles.
  5. Inadequate testing: The absence of test code introduces many errors that may only be discovered later. This situation is undesirable in clean code development.


What is Clean Code?
In short, Clean Code can be defined as code that is easy to understand and modify, despite being a subjective concept. Whether the reader is the author of the code or someone else, they should be able to read and comprehend it in a natural flow.
In Clean Code:

  • The execution flow of the entire application,
  • How different objects collaborate with each other,
  • The role and responsibility of each class,
  • What each method does,
  • The purpose of each expression and variable,

are easy to understand.

  • Classes and methods are small and have a single responsibility.
  • Predictable methods are employed.
  • The code is easily testable.


Write & Read to Earn with BULB

Learn More

Enjoy this blog? Subscribe to feridebeyazgull

1 Comment

B
No comments yet.
Most relevant comments are displayed, so some may have been filtered out.