Clean code principles that you need to know part 1

Gauloran

Kıdemli Moderatör
7 Tem 2013
8,096
585
local
clean_Code.png


well clean code principles are very important for create some projects they are a set of guidelines and best practices aimed at producing maintainable and efficient code. in this topic im going to show you these principles with examples in dart programming language

first you have to use descriptive names for variables and functions etc. its very important rule

rule -1
Kod:
//bad example
var a = 100;


//good example
var money = 100;

rule -2

each function or class should have a single responsibility, they should do one thing well for example
Kod:
//bad one
void userData(){
 //code to handle user input, update UI, other things etc.
.. bla bla ITS BAD


//good example
void handleUserInput(){
 //code to handle user input JUST FOR THIS
.... .....


void updateUI(){
 //JUST CODE TO UPDATE UI
//good example

rule -3

do not repeat yourself you should avoid duplicating code basically
Kod:
//bad example
for text1
Textstyle: Colors.red,
for text2
Textstyle: Colors.red,
for text3
Textstyle: Colors.red,


//good example


for all textstyles : Theme.of(context).....textStyles.colors.red... etc

rule -4
code formatting is very important to read the code
Kod:
// Bad example
void calculateSum(){var a=5;var b=10;print(a+b);}


// Good examplevoid calculateSum() {
 var a = 5;
 var b = 10;
 print(a + b);
}

well these rules can help you to code better I'll share other rules when I remember them
good luck

<3 Gauloran​
 

rootibo

Kıdemli Üye
13 Mar 2023
2,168
1,459
clean_Code.png


well clean code principles are very important for create some projects they are a set of guidelines and best practices aimed at producing maintainable and efficient code. in this topic im going to show you these principles with examples in dart programming language

first you have to use descriptive names for variables and functions etc. its very important rule

rule -1
Kod:
//bad example
var a = 100;


//good example
var money = 100;

rule -2

each function or class should have a single responsibility, they should do one thing well for example
Kod:
//bad one
void userData(){
 //code to handle user input, update UI, other things etc.
.. bla bla ITS BAD


//good example
void handleUserInput(){
 //code to handle user input JUST FOR THIS
.... .....


void updateUI(){
 //JUST CODE TO UPDATE UI
//good example

rule -3

do not repeat yourself you should avoid duplicating code basically
Kod:
//bad example
for text1
Textstyle: Colors.red,
for text2
Textstyle: Colors.red,
for text3
Textstyle: Colors.red,


//good example


for all textstyles : Theme.of(context).....textStyles.colors.red... etc

rule -4
code formatting is very important to read the code
Kod:
// Bad example
void calculateSum(){var a=5;var b=10;print(a+b);}


// Good examplevoid calculateSum() {
 var a = 5;
 var b = 10;
 print(a + b);
}

well these rules can help you to code better I'll share other rules when I remember them
good luck

<3 Gauloran​
omg so nice topic
 
Ü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.