Collaboration: Coding Together 🤝💻
Writing code alone is like playing a single-player game. Working in a team is like a multiplayer game. You need to coordinate so you don't crash into each other.
In software, we use tools like Git to manage this coordination.
The "Shared State" Problem ⚔️
Imagine you and a friend are editing the same Python file at the same time on Google Drive.
- You change line 10.
- Friend changes line 10.
- Conflict! Who wins?
This is a Race Condition. We avoid this using Version Control.
The Workflow: Branches & Pull Requests 🌿
Instead of editing the "Main" code directly, we create a copy.
1. The Branch (The Copy)
You create a separate workspace called a Branch.
mainbranch: The working game.feature-jumpbranch: Your playground to add jumping.
You can break everything in your branch, and the main game is safe.
2. The Pull Request (The Review) 🔍
When you are done, you don't just "Save". You ask for a Pull Request (PR). This is like handing your homework to a friend to check for mistakes before handing it to the teacher.
Why Review?
- Catch Bugs: "Hey, this
whileloop runs forever!" - Learn: "Did you know there is a simpler way to sort this list?"
- Style: "Please add spaces around the
=sign."
3. The Merge (The Save) 💾
Once your friend says "Looks Good To Me" (LGTM), you Merge your branch into main. Now everyone has your new feature.
Pair Programming: Coding with a Co-Pilot ✈️
Sometimes, instead of reviewing code after, we review it while writing it.
Two people, one computer.
- The Driver: Has the keyboard. Focuses on typing correct syntax.
- The Navigator: Watches the screen. Focuses on the big picture ("What if the user enters -1?").
Benefit: You spot bugs instantly. Two brains are better than one.
The "Bus Factor" 🚌
Question: If the only person who understands the code wins the lottery and leaves, what happens?
- Bus Factor = 1: The project dies. (Bad!)
- Bus Factor = High: Everyone knows how it works because you did Code Reviews. (Good!)
Task: The Code Review 🧐
Task
Scenario: Your teammate wrote this function. Review it. What feedback would you give?
def c(x):
# calculates stuff
return x * 1.8 + 32Possible Feedback
- Naming: Rename
ctocelsius_to_fahrenheitso we know what it does. - Documentation: Add a docstring explaining the math.
- Variables: Rename
xtocelsius.