In the software world, it is often possible to encounter situations where a process is carried out due to some deficiencies, as well as being performed perfectly. At this point, even though the transaction was not carried out in a professional manner, the background does not matter much since the result is positive. The concept of clean code emerged based on this evaluation. In this content, we will tell you about the principles of coding. clean code We will talk about the concept and talk about its basic dynamics.
What is Clean Code?

If the code to be written is error-free, easily understandable, editable, collapsible or expandable, this code is called clean code. What is cleancode? The question can be answered in this shortest way. Of course, it is not possible to talk about the entire evaluation in a few sentences. Important information about the concept in general terms is as follows.
- It should be simple to think and simple to implement. Avoiding confusion is the most important feature of the concept.
- The code should be written in an easily editable way, considering yourself or the people who will edit the code after you.
- Concept written by Robert Cecil Martin “Clean Code” It was associated with the book and emerged from there.
The dynamics of the concept are very simple and have great importance in the software world. It is a concept introduced to eliminate errors in easily understandable code writing and to write more easily editable codes. For this reason, it is extremely important and a necessity for regular study.
How to Write Clean Code?

The code must be easy to understand. This is the basic dynamic. However, in order for a code to be included in the concept, the code must be easily understandable not only for the person who wrote the code, but also for another person who will later read and edit the code. In case it is not so “Bad Code” concept is encountered. It is noteworthy that the code is not easily understandable, as the bad code cannot be attributed to a human qualification. Other important factors are as follows.
- You should be simple, write simple and read simple.
- You should leave a simpler environment for those who will deal with the code after you.
- You must clear it of errors and omissions. The fact that it works without errors does not change the fact that it is bad code.
- Do not reduce readability with complex codes. Try simpler code styles.
- You should be flexible with many different structures using polymorphism.
- Be careful to use Dependency Injection. Thus, the code is free of all dependencies and can be edited independently.
- The variable, function/method, and class names you use must be clear and descriptive. You should pay attention to this.
- You must make the naming correctly. It is very important to be able to search easily later.
- The functions you use should not perform more than one operation. You should only code functions that do their own job.
- You should avoid functions that contain Side Effects.
- You should not use unnecessary comment lines and your comment lines should be descriptive.
- The flow direction of the functions should be downwards and should not disrupt the indents.
- Be careful to use non-static methods.
As seen above, the above dynamics should be taken into consideration in order to create clean code. Of course, the implementation of all these dynamics will depend on the person who writes and reads the code. For this reason, you should always try to be simple and read simply.
What is Bad Code?

When it comes to the person who wrote the code and the time the code was written; Considering issues such as time, wrong system, administrative errors, bad codes may emerge. In this context, codes that do not meet the clean code criteria and are not correct and functional, bad code is called. So, how to detect bad code?
- If it is difficult to read and understand,
- If making changes has become almost impossible,
- If there is a lot of unnecessary code and the codes are difficult to read, we can say that you are faced with bad code.
So, is there really such a thing as bad code? It is not difficult to find literature in which this concept is used. However, there are also literatures stating that such a concept should not be used. This is because bad code can have different connotations for everyone. For this reason, it is recommended not to use the concept of bad code.
Robert Cecil Martin's classic “Clean Code” We can come across this concept in his book. There is text in the book that even bad code can work. So the concept of bad code is mentioned. However, it should not be too difficult to say that there are already disagreements on this issue. Considering that we often encounter the concept of "This code is bad. We should refactor it.", it is clear that such a concept exists and should be included in the literature. So, does the code smell? Let's examine this.
What is Code Smells?

In Turkish, it is possible to make a better expression with a metaphor, that is, a non-literal meaning. So much so that this situation has greatly improved our Turkish and strengthened the expression. Here code smells, so code smelling bad is also an example of this. Metaphor, but a great explanation. Well, What is code smells?
If there are parts of the written code that are not understood, if unnecessary codes have been made and repeated, if what is intended to be explained is extended and nothing is understood when read, a bad smell is coming to your nose. Yes, this code is now a smelly code, that is, code smells. Of course, there are different dynamics here. It is necessary to pay attention to these separately.
How to Identify Code Smells?

Even if it performs its function fully, codes that perform this in a long and incomprehensible way are in the bad-smelling code class. The concepts that are at the forefront for this can be listed as follows.
- Duplication (Repeating code): It is valid if there are repeating sections and you can copy and paste this code structure. See also: Don't Repeat Yourself (DRY) principle
- Obscurity: This concept attracts attention if the code is incomprehensible and difficult to read.
- Rigidity: It cannot be changed, even if it is changed, it will be valid if many places are affected.
- Verbose code (Unnecessarily long code): This concept is valid if you overcomplicate the action you can do in a simpler way.
When you carefully examine the above concepts and their explanations, you can easily understand code smells.
In this content for you What is clean code? How to write clean code? What is bad code? What is code smells? We answered many questions such as and explained them in detail. You can also contribute to our content by expressing your opinions and suggestions in the comments section.
Frequently Asked Questions
We have compiled a few frequently asked questions about clean code for you.



