Code Review Processes
Code Review nima?โ
Code Review - bu sizning yozgan kodingizni boshqa dasturchilar ko'rib chiqib, taklif va tuzatishlar berishidadir.
Bu xuddi maktabda inshoni tekshirib berish kabi - lekin kod uchun! ๐
Nima uchun Code Review kerak?โ
1. Xatolarni topish ๐โ
# Reviewer topishi mumkin:
if user.age > 18: # Nima uchun faqat 18?
return True
# Taklif: >= 18 bo'lishi kerakmi?
2. Kod sifatini yaxshilash โจโ
// Yomon kod:
function calc(a, b) {
return a + b * 2 - 5; // Bu nima qiladi?
}
// Reviewer taklifi:
function calculateDiscountedPrice(originalPrice, taxRate) {
const priceWithTax = originalPrice + (originalPrice * taxRate);
const discount = 5;
return priceWithTax - discount;
}
3. Bilim almashish ๐คโ
- Yangi dasturchilar o'rganadi
- Tajribali dasturchilar bilim ulashadi
- Jamoaning kod yazish uslubi bir xil bo'ladi
4. Xavfsizlik ๐โ
# Xavfli:
password = request.form['password'] # Hash qilinmagan!
# Reviewer topadi:
password = hash_password(request.form['password'])
Code Review jarayoniโ
1. Pull Request yaratishโ
# Feature branch da ishlash
git checkout -b feature/user-login
# ... kod yozish ...
git add .
git commit -m "User login funksiyasi qo'shildi"
git push origin feature/user-login
2. PR ning yaxshi tavsifiโ
## O'zgarishlar
### Nima qilindi:
- User login page yaratildi
- Password validation qo'shildi
- Session management sozlandi
### Test:
- โ
Unit testlar o'tdi
- โ
Manual testing bajarildi
- โ
Edge case lar tekshirildi
### Screenshot:

### Checklist:
- [x] Kod test qilindi
- [x] Documentation yangilandi
- [x] No breaking changes
3. Reviewer tanlashโ
# CODEOWNERS fayli
# Global
* @senior-dev @team-lead
# Frontend
/frontend/ @frontend-team @ui-designer
# Backend API
/api/ @backend-team @api-architect
# DevOps
/docker/ @devops-team
/k8s/ @devops-team @infra-team
4. Review jarayoniโ
Reviewer ning vazifasi:โ
a) Kod mantiqini tekshirish:
# Reviewer savolli:
def divide_numbers(a, b):
return a / b # b=0 bo'lsa nima bo'ladi?
# Taklif:
def divide_numbers(a, b):
if b == 0:
raise ValueError("Bo'luvchi nolga teng bo'lishi mumkin emas")
return a / b
b) Performance ni tekshirish:
// Savollar:
users.forEach(user => {
database.save(user); // Har bir user uchun alohida DB call?
});
// Taklif:
database.bulkSave(users); // Batch save
c) Security tekshirish:
-- Xavfli:
query = f"SELECT * FROM users WHERE id = {user_id}" -- SQL Injection!
-- Xavfsiz:
query = "SELECT * FROM users WHERE id = %s"
cursor.execute(query, (user_id,))
Review Typesโ
1. Formal Reviewโ
- Rasmiy jarayon
- Ko'p reviewerlar (2-3 kishi)
- Detailed checklist
- Enterprise loyihalar uchun
2. Lightweight Reviewโ
- Tez jarayon
- 1-2 reviewer
- Asosiy narsalarni tekshirish
- Startup/Agile uchun
3. Pair Programmingโ
- Real-time review
- Ikki kishi birga kod yozadi
- Darhol feedback
- Complex vazifalar uchun
Review da nimalarni tekshirish?โ
1. Functionality โ๏ธโ
- Kod ishlayaptimi?
- Requirements ni qondiraptimi?
- Edge case lar handle qilinganmi?
2. Code Quality ๐โ
# Yaxshi kod:
def calculate_user_age(birth_date: datetime) -> int:
"""
User yoshini hisoblash
Args:
birth_date: User tug'ilgan sana
Returns:
int: Yosh (yillarda)
"""
today = datetime.now()
return today.year - birth_date.year
3. Performance ๐โ
# Yomon:
for user in users:
for role in user.roles: # O(nยฒ)
# ...
# Yaxshi:
user_roles = {user.id: user.roles for user in users} # O(n)
4. Security ๐โ
# Tekshirish kerak:
- Input validation
- Authentication/Authorization
- Sensitive data handling
- SQL injection prevention
- XSS protection
5. Maintainability ๐งโ
- Kod o'qish osonmi?
- Comments yetarlimi?
- Function lar kichikmi?
- Naming conventions to'g'rimi?
Review Commentsโ
Yaxshi comment yozish:โ
โ Yomon:
Bu yomon
Fix this
Wrong approach
โ Yaxshi:
Bu yerda potential memory leak bo'lishi mumkin.
`close()` methodini `finally` block da chaqirishni taklif qilaman.
Misol:
try:
file = open('data.txt')
# ...
finally:
file.close()
Comment turlari:โ
1. Must Fix (Majburiy) ๐ด
โ BLOCKER: SQL injection vulnerability bu yerda.
Parameter binding ishlatishingiz kerak.
2. Should Fix (Tavsiya) ๐ก
๐ก SUGGESTION: Bu function juda uzun. Kichik functionlarga
bo'lishni taklif qilaman readability uchun.
3. Nice to Have (Ixtiyoriy) ๐ข
โจ NICE: Bu yerda caching qo'shsangiz performance yaxshilanadi.
Keyingi iteration da qo'shishingiz mumkin.
4. Question (Savol) โ
โ QUESTION: Bu magic number (42) nimani anglatadi?
Constant sifatida e'lon qilsak yaxshi bo'ladi.
5. Praise (Maqtash) ๐
๐ GREAT: Bu error handling juda yaxshi qilingan!
Edge case larni ham handle qibsiz.
Review Tools va Platformsโ
1. GitHub Pull Requestsโ
# Review features:
- Line-by-line comments
- Suggestions (kod o'zgartirish takliflari)
- Approve/Request changes
- Draft PRs
- Review assignments
2. GitLab Merge Requestsโ
# Advanced features:
merge_request:
approvals_required: 2
reset_approvals_on_push: true
disable_overriding_approvers: true
3. Azure DevOpsโ
{
"reviewerPolicy": {
"minimumApproverCount": 2,
"resetOnSourcePush": true,
"blockLastPusherVote": true
}
}
4. Bitbucketโ
- Built-in code insights
- Jira integration
- Smart suggestions
Automated Code Reviewโ
1. Linting Toolsโ
# .github/workflows/lint.yml
name: Code Quality
on: [pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ESLint
run: |
npm install
npm run lint
- name: Run Pylint
run: |
pip install pylint
pylint *.py
2. Code Coverageโ
# Coverage requirement
coverage:
range: 80..100
round: down
precision: 2
status:
project:
default:
target: 80%
threshold: 5%
3. Security Scanningโ
# Automated security review
security:
- name: Run Snyk
uses: snyk/actions/node@master
with:
args: --severity-threshold=high
4. Code Quality Toolsโ
# SonarQube integration
sonar-scanner \
-Dsonar.projectKey=myproject \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=$SONAR_TOKEN
Review Metrics va KPIsโ
1. Speed Metricsโ
- PR ochilgandan approve gacha vaqt
- First response time
- Time to merge
2. Quality Metricsโ
- Defect discovery rate
- Post-release bugs
- Code coverage improvement
3. Team Metricsโ
- Review participation rate
- Review thoroughness
- Knowledge sharing index
DevOps uchun Code Reviewโ
1. Infrastructure as Code Reviewโ
# Terraform review checklist:
- โ
Resource naming conventions
- โ
Security groups properly configured
- โ
No hardcoded secrets
- โ
Proper tagging
- โ
Cost optimization
# Kubernetes review:
- โ
Resource limits set
- โ
Security contexts defined
- โ
Proper labels and selectors
- โ
ConfigMaps instead of hardcoded values
2. Pipeline Reviewโ
# CI/CD pipeline review:
- โ
Proper error handling
- โ
Secure credential usage
- โ
Rollback strategy defined
- โ
Test coverage adequate
- โ
Deployment strategy safe
3. Docker Reviewโ
# Dockerfile best practices:
- โ
Multi-stage builds
- โ
Non-root user
- โ
Minimal base image
- โ
.dockerignore file
- โ
Health checks defined
Common Review Problems va Solutionsโ
1. Review Bottlenecks ๐ซโ
Problem: PRlar uzoq kutadi
Solution:
# Automated assignment
code_review:
auto_assign:
- team: backend
files: ["*.py", "*.go"]
- team: frontend
files: ["*.js", "*.vue"]
round_robin: true
max_reviewers: 2
2. Review Quality ๐โ
Problem: Sust review
Solution:
- Review checklist yarating
- Training o'tkazing
- Review metrics tracking
- Good/bad example lar ko'rsating
3. Large PRs ๐ฆโ
Problem: Katta PR larni review qilish qiyin
Solution:
# PR size limits
if [[ $(git diff --name-only | wc -l) -gt 20 ]]; then
echo "โ PR juda katta! 20 ta fayldan ko'p"
exit 1
fi
Best Practicesโ
1. Author uchun:โ
- โ Kichik, focused PR lar yarating
- โ Self-review qiling yuborishdan oldin
- โ Yaxshi tavsif yozing
- โ Test qo'shing
- โ Documentation yangilang
2. Reviewer uchun:โ
- โ Tez javob bering (24 soat ichida)
- โ Constructive feedback bering
- โ Code o'rniga problem ga focus qiling
- โ Positive feedback ham bering
- โ Questions so'rang, tushunmagan joylarni
3. Team uchun:โ
- โ Review culture yarating
- โ Guidelines belgilang
- โ Tools va automation ishlatang
- โ Metrics track qiling
- โ Continuous improvement
Review Checklist Templateโ
## Code Review Checklist
### Functionality โ๏ธ
- [ ] Kod ishlayaptimi?
- [ ] Requirements qondirilganmi?
- [ ] Edge cases handle qilinganmi?
- [ ] Error handling to'g'rimi?
### Code Quality ๐
- [ ] Naming conventions to'g'rimi?
- [ ] Functions kichik va focused mi?
- [ ] DRY principle qo'llanganmi?
- [ ] Comments yetarlimi?
### Performance ๐
- [ ] Efficient algorithms ishlatilganmi?
- [ ] Database queries optimized mi?
- [ ] Memory leaks yo'qmi?
- [ ] Caching qo'llanganmi?
### Security ๐
- [ ] Input validation qilinganmi?
- [ ] Authentication/authorization to'g'rimi?
- [ ] Sensitive data secure mi?
- [ ] SQL injection himoyasi bormi?
### Testing ๐งช
- [ ] Unit tests yozilganmi?
- [ ] Test coverage yetarlimi?
- [ ] Integration tests bormi?
- [ ] Manual testing qilinganmi?
### DevOps ๐ง
- [ ] Docker configuration to'g'rimi?
- [ ] Environment variables ishlatilganmi?
- [ ] CI/CD pipeline ishlayaptimi?
- [ ] Monitoring/logging qo'shilganmi?
Xulosaโ
Code Review - bu zamonaviy dasturlashning ajralmas qismi:
โ
Quality Assurance - kod sifatini ta'minlash
โ
Knowledge Sharing - bilim almashish
โ
Bug Prevention - xatolarni oldindan topish
โ
Team Growth - jamoaning rivojlanishi
โ
Standards Compliance - standartlarga rioya qilish
DevOps engineer sifatida review processni yaxshilash orqali butun development lifecycle ni optimize qilishingiz mumkin!