DEV Community

Ramziddin Makhmudov
Ramziddin Makhmudov

Posted on

⚠️ Eng keng tarqalgan dasturlash xatosi!

DRY Principle — yani Don't Repeat Yourself, O'zingizni takrorlamang.

Agar 10 sahifada siz bir xil tugmani yaratgan bo'lsangiz...Misol:

index.html

<button style="padding: 10px; border-radius: 8px; color: white; background: black;">
  Ma'lumot olish
</button>
Enter fullscreen mode Exit fullscreen mode

contacts.html

<button style="padding: 10px; border-radius: 8px; color: white; background: black;">
  Aloqaga chiqish
</button>
Enter fullscreen mode Exit fullscreen mode

socials.html

<button style="padding: 10px; border-radius: 8px; color: white; background: black;">
  Obuna bo'lish
</button>
Enter fullscreen mode Exit fullscreen mode

Va hokazo.

Har bir sahifadagi tugmani o'zgartirish kerak bo'lganda nima bo'lishini tasavvur qiling...

Agar sizda 10, 50, 100 sahifa bo'lsa-chi?

Har bir sahifada "padding" ni o'zgartirishingiz kerak bo'ladi. Bu sizga bir necha soat vaqt oladi!

Shuning uchun kodni ikki yoki undan ortiq takrorlash aqlli emas.

Buning yechimi nima? "class" dan foydalaning.

styles.css

.btn {
  padding: 10px;
  border-radius: 8px;
  color: white;
  background: black;
}
Enter fullscreen mode Exit fullscreen mode

index.html

<button class="btn">
  Ma'lumot olish
</button>
Enter fullscreen mode Exit fullscreen mode

contacts.html

<button class="btn">
  Aloqaga chiqish
</button>
Enter fullscreen mode Exit fullscreen mode

socials.html

<button class="btn">
  Obuna bo'lish
</button>
Enter fullscreen mode Exit fullscreen mode

Endi barcha tugmalarning ranglarini o'zgartirish kerak bo'lsa nima bo'ladi? Siz shunchaki atiga styles.css faylini o'zgartirishingiz kerak.

Oldest comments (4)

Collapse
 
azizc0der profile image
Azizxo'ja Saidrahmonov

🔥🔥

Collapse
 
zafarbekde profile image
Zafarbek • Edited

Yana bir yoli bor ID bilan qilsa bo'ladi

Collapse
 
javohirdev profile image
Khamidullaev Javohir

Lekin maslahat berilmaydi.

Collapse
 
dovlatbek profile image
Dovlatbek

rahmat bro!