How to Start Writing Clean Code

Gauloran

Moderasyon Ekibi Lideri
7 Tem 2013
8,189
641
How to Start Writing Clean Code

Maybe some of you know the IT conversations organized by Mimar Aslan. We chat with experts from IT every week, different topics are discussed. I listened the chat about "how to we use clean code" with Akın Kaldıroğlu. During the conversation, Aslan's words caught my attention. He said "I only wrote code just once in my life from the beginning.

What does it mean? When we enter the business world, they won't tell us "buy this program, write this program" Because we will edit a written code. So, what is the biggest problem? Well it is very difficult to understand the code. Because you have to view from the beginning. What is the reason for this? Yeah we can type the desired code somehow, the code works but when someone else reads the code and says "what the hack is this!!?" that means the code is clean.

File structure

For example, if we are doing web programming it is necessary to plan the file structures first. If both our html page, js / css files and images etc. are in the same folder, it will be very difficult to search and find something in the folder.

Comment Lines

I think the comments lines are our best friend when typing the code. We defined a function, wrote the codes. So, when we read that code after 2 months later or when someone else looks at it he shouldn't say "what is this function doing?"

Variable names

We use variables when typing code. I would define int a or int b, int c in order not to waste time when I first started. However, 1 week later and I open the code but I don't understand my variables because of their names.

Spelling Standarts

Everyone has certain spelling standarts, they come up automatically as we type the code. For example when i run a form application in C#, I give my variables names such as textBoxAd, txtBoxYas, comboBoxOkul. As I wrote textbox, all textboxes such as textboxad, textboxyas etc. will be listed. And when the person reading the code sees the textbox1.text, it will make sure that they don't look at the wrong textbox. typing the name of a function that performs the addition, it is useful to type the first letter lowercase and the initials of the words that will follow.

An example function definition:
Kod:
_Addition(int number1, number2){
sum = number1 + number2; 
return total;
}

Every function should have a purpose. You can't do everything with one function. Can you? If we are constantly repeating some things in the code, we should try to handle them with a function. I mean, save the time. One day, the code you wrote will surely reach the hands of other programmers and those codes will be understood. You know "leave it as you would wish to find it"


Source:https://www.turkhackteam.org/bilgi-guvenligi-teknolojisi/1185786-temiz-kod-yazmak.html

Translator Gauloran
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.