Lý thuyết
25 phút
Bài 12/12

Best Practices & Productivity Tips

Tổng kết các best practices và tips để tối đa hóa hiệu quả với GitHub Copilot

Best Practices & Productivity Tips

1. Course Recap

Những gì bạn đã học

Skills Acquired

SkillBài học
Copilot AutocompleteBài 3
Prompt EngineeringBài 4
Copilot ChatBài 5
Agent ModeBài 6
Code ReviewBài 7
RefactoringBài 8
TestingBài 9
Full-stack DevelopmentBài 10-11

2. The Vibe Coding Mindset

Từ "Viết Code" sang "Điều khiển AI"

Mindset Shift

Coding Approach
Traditional Coding
Type every character
Search documentation
Debug by print/log
Write tests manually
Vibe Coding
Describe what you want
Ask Copilot directly
Debug with Chat
Generate tests with /tests

Core Principles

markdown
11. **Describe Intent, Not Implementation**
2 - Good: "Add user authentication with JWT"
3 - Bad: "Write a function that takes username..."
4
52. **Think in Components/Functions**
6 - Break down into small pieces
7 - Let Copilot implement each piece
8
93. **Review, Don't Trust Blindly**
10 - Always review generated code
11 - Test before committing
12
134. **Iterate Rapidly**
14 - Quick feedback loops
15 - "Make it work, make it right, make it fast"

3. Productivity Best Practices

3.1 Keyboard Shortcut Mastery

ShortcutActionFrequency
TabAccept suggestion⭐⭐⭐⭐⭐
EscDismiss suggestion⭐⭐⭐⭐
Ctrl+EnterShow alternatives⭐⭐⭐
Ctrl+IInline chat⭐⭐⭐⭐⭐
Ctrl+Alt+IChat panel⭐⭐⭐⭐
Ctrl+Shift+IAgent mode⭐⭐⭐

3.2 File Naming for Better Suggestions

Bash
1# Good - Copilot understands context
2user_service.py # Service for users
3auth_middleware.js # Authentication middleware
4product_api_test.py # Tests for product API
5
6# Less clear
7helpers.py
8utils.js
9test_stuff.py

3.3 Comment-Driven Development

Python
1# Step 1: Write clear comment describing what you need
2# Implement a rate limiter using sliding window algorithm
3# - Max 100 requests per minute per IP
4# - Use Redis for storage
5# - Return 429 status when limit exceeded
6
7# Step 2: Let Copilot generate
8# Step 3: Review and refine

4. Prompt Templates Library

4.1 Feature Implementation

markdown
1**Template:**
2Implement [FEATURE_NAME] for [CONTEXT]:
3- Requirements: [LIST]
4- Input: [DESCRIPTION]
5- Output: [DESCRIPTION]
6- Edge cases: [LIST]
7- Error handling: [EXPECTATIONS]
8
9**Example:**
10Implement user registration for a Flask app:
11- Requirements: email, password, name fields
12- Input: JSON body with user data
13- Output: Created user object with JWT token
14- Edge cases: duplicate email, invalid format
15- Error handling: Return 400 with specific messages

4.2 Bug Fix

markdown
1**Template:**
2Fix the bug in [FILE/FUNCTION]:
3- Current behavior: [WHAT_HAPPENS]
4- Expected behavior: [WHAT_SHOULD_HAPPEN]
5- Steps to reproduce: [STEPS]
6- Error message: [IF_ANY]
7
8**Example:**
9Fix the bug in calculateTotal():
10- Current behavior: Returns NaN for empty cart
11- Expected behavior: Return 0 for empty cart
12- Steps: Create cart, don't add items, call calculateTotal()

4.3 Code Review

markdown
1**Template:**
2Review this code for:
31. Security vulnerabilities
42. Performance issues
53. Best practices violations
64. Edge cases not handled
7
8Format response as:
9🔴 Critical: [MUST FIX]
10🟡 Warning: [SHOULD FIX]
11🟢 Suggestion: [NICE TO HAVE]

4.4 Refactoring

markdown
1**Template:**
2Refactor [CODE] to:
3- Apply [PATTERN/PRINCIPLE]
4- Improve [ASPECT: readability/performance/testability]
5- Maintain backward compatibility: [YES/NO]
6- Add tests: [YES/NO]

4.5 Testing

markdown
1**Template:**
2Generate tests for [FUNCTION/CLASS]:
3- Test framework: [pytest/jest/etc]
4- Coverage: [unit/integration/e2e]
5- Include: happy path, edge cases, error cases
6- Mock: [LIST_DEPENDENCIES]

5. Common Anti-Patterns

❌ DON'T

Python
1# 1. Vague prompts
2"Make this better"
3"Fix the bug"
4"Add feature"
5
6# 2. Accepting without review
7# Just press Tab on everything
8
9# 3. Overcomplicating prompts
10"Write a function that implements the observer pattern
11with dependency injection using a factory method
12that also handles async operations with proper
13error boundaries and retry logic with exponential
14backoff and circuit breaker pattern..."
15
16# 4. Ignoring context
17# Not using @workspace when needed
18# Not providing relevant files
19
20# 5. Fighting Copilot
21# Manually editing when regenerating would be faster

✅ DO

Python
1# 1. Specific prompts
2"Add email validation using regex, return boolean"
3"Fix NullPointerException on line 45"
4"Add pagination to GET /users endpoint"
5
6# 2. Review before accepting
7# Read the code, understand it, test it
8
9# 3. Break down complex requests
10"First, create the data model"
11"Next, add the API endpoint"
12"Finally, write the tests"
13
14# 4. Leverage context
15"@workspace how does auth work in this project?"
16
17# 5. Iterate with Copilot
18"Good, but also add input validation"
19"Make this async"
20"Add error handling"

6. Language-Specific Tips

Python

Python
1# Use type hints - better suggestions
2def process_order(order: Order, user: User) -> Receipt:
3 # Copilot understands types
4
5# Use docstrings
6def calculate_tax(amount: float, rate: float) -> float:
7 """
8 Calculate tax amount.
9
10 Args:
11 amount: Base amount
12 rate: Tax rate (0.1 = 10%)
13
14 Returns:
15 Tax amount
16 """
17 # Copilot generates implementation

JavaScript/TypeScript

TypeScript
1// TypeScript interfaces help Copilot
2interface User {
3 id: string;
4 name: string;
5 email: string;
6 role: 'admin' | 'user';
7}
8
9// JSDoc for JavaScript
10/**
11 * @param {string} userId
12 * @returns {Promise<User>}
13 */
14async function getUser(userId) {
15 // Better suggestions
16}

React

tsx
1// Props interface = better component suggestions
2interface ButtonProps {
3 variant: 'primary' | 'secondary';
4 size: 'sm' | 'md' | 'lg';
5 onClick: () => void;
6 children: React.ReactNode;
7}
8
9// Component with clear props
10function Button({ variant, size, onClick, children }: ButtonProps) {
11 // Copilot knows what to generate
12}

7. Team Workflows

7.1 Code Review với Copilot

markdown
1## PR Review Checklist with Copilot
2
3### Before Reviewing
41. Read PR description
52. Understand the feature/fix
6
7### Review Process
81. Use `/explain` on complex changes
92. Ask about potential issues
103. Request security review
114. Check test coverage
12
13### Feedback Format
14- Use Copilot to suggest improvements
15- Reference docs/patterns when needed

7.2 Pair Programming

markdown
1## Copilot as Pair Partner
2
3Driver (You):
4- Define what to build
5- Review suggestions
6- Make decisions
7
8Navigator (Copilot):
9- Generate code
10- Suggest alternatives
11- Explain approaches

7.3 Onboarding New Members

markdown
1## Using Copilot for Onboarding
2
31. **Understanding Codebase**
4 @workspace explain the architecture of this project
5
62. **Finding Examples**
7 @workspace show me examples of API endpoints
8
93. **Learning Patterns**
10 @workspace what patterns does this project use?
11
124. **Running Project**
13 @workspace how do I set up and run this project?

8. Staying Up-to-Date

8.1 New Features

GitHub Copilot được update thường xuyên:

  • Copilot Chat improvements
  • Agent mode enhancements
  • New slash commands
  • Better context understanding

8.2 Resources

markdown
1## Keep Learning
2
3📚 Documentation
4- https://docs.github.com/copilot
5
6📺 YouTube
7- GitHub channel
8- VS Code channel
9
10🐦 Twitter/X
11- @GitHubCopilot
12- @code
13
14💬 Community
15- GitHub Discussions
16- VS Code Discord

9. Productivity Metrics

Tracking Your Progress

markdown
1## Weekly Copilot Metrics
2
3### Quantitative
4- Lines of code assisted: ___
5- Suggestions accepted: ___%
6- Time saved (estimate): ___ hours
7
8### Qualitative
9- Most helpful feature this week: ___
10- Challenge overcome with Copilot: ___
11- New technique learned: ___
12
13### Goals for Next Week
14- Try: ___
15- Improve: ___

Before vs After

TaskBefore CopilotWith Copilot
Write CRUD API2 hours30 minutes
Write unit tests1 hour15 minutes
Debug complex issue1+ hour20 minutes
Learn new frameworkDaysHours
Code review30 min10 minutes

10. Final Checklist

Copilot Mastery Checklist

markdown
1## Basics
2- [ ] Efficient use of autocomplete
3- [ ] Comfortable with inline chat
4- [ ] Know all important shortcuts
5
6## Intermediate
7- [ ] Effective prompt engineering
8- [ ] Using @workspace context
9- [ ] Code review with Copilot
10
11## Advanced
12- [ ] Agent mode for complex tasks
13- [ ] TDD with generated tests
14- [ ] Refactoring workflows
15
16## Expert
17- [ ] Custom prompt templates
18- [ ] Team workflow integration
19- [ ] Teaching others

11. Chứng chỉ hoàn thành

🎉 Chúc mừng bạn đã hoàn thành khóa học Vibe Coding với GitHub Copilot!

Bạn đã học được:

  1. Vibe Coding Philosophy - Cách tiếp cận mới trong lập trình
  2. Copilot Fundamentals - Autocomplete, Chat, Agent mode
  3. Prompt Engineering - Viết prompts hiệu quả
  4. Code Quality - Review, refactoring, testing
  5. Full-stack Development - Xây dựng ứng dụng hoàn chỉnh
  6. Best Practices - Tips và workflows

Tiếp theo của bạn:

markdown
11. **Practice Daily**
2 - Use Copilot for all coding tasks
3 - Experiment with new features
4
52. **Build Projects**
6 - Apply skills to real projects
7 - Challenge yourself
8
93. **Share Knowledge**
10 - Help others learn
11 - Share tips and tricks
12
134. **Stay Updated**
14 - Follow GitHub Copilot news
15 - Try new features as released

Quote để kết thúc

"The best way to predict the future is to invent it." — Alan Kay

Với Vibe Coding và GitHub Copilot, bạn đang tạo ra tương lai của lập trình!


Resources

Official

Community

Practice


🚀 Chúc bạn code vui vẻ với GitHub Copilot!