When you just start out on your learning journey toward becoming a developer, you primarily work with code that only you have written and that only you will use. But as you progress, one of the big milestones you’ll come across is when you begin to work with code written by someone else.
When you start working with code written by someone else, it might be within a team in a workplace, but it might also be as part of the larger open source community online. There are a few potential stumbling blocks and things you should know before you take this next step.
From solo developer to team player
The benefit of writing your own code as you begin is that you truly get a handle on core concepts and what each and every part of the program is for. But as you take part in the larger developer community, you’ll need to start working with other developers and their code. One of the biggest hurdles that new developers encounter is learning how to understand code written by someone else.
When you start taking part in larger programming projects, there may be 2 or even 30 other developers contributing code. The trouble is, some of the code you need to understand may be messy or complicated. It may also use data structures or design patterns that you’ve never seen before. When you’re a new developer, this can be quite intimidating. So, we’ve put together 10 tips to help you understand someone else’s code.
10 tips for working with someone else’s code
If you follow these 10 tips, you’ll be on the right track toward making a difference in the codebase.
1. It’s only code
Remember — it’s not a foreign language. It’s just code. You can figure it out, no matter how intimidating or overwhelming it may look. If you’re working on this project, then you probably know the language can trust in your abilities.
In bigger projects and codebases, however, there may be libraries, frameworks, and external APIs that you won’t be familiar with. A good first step, then, is to identify these dependencies in the code.
2. Set up your environment
Most of the projects that you’ll work on with a team require your local machine to be set up in a specific way. This does two things: It ensures that both your environment and your teammates’ environments are the same, and it will allow the code to perform as intended.
To set up the environment on your laptop or desktop, you may need to do the following:
- Modify your computer’s host file
- Download and install external programs
- Use special IDEs or text editors
- Change the version of a program on your computer
- Log into a VPN
“This is the most important part and the most annoying part, especially if you’re dealing with complicated codebases,” shares Mike, the developer in the video above.
3. Run the tests
If you’re a new developer, you may not have much experience with running tests. But any codebase worth its salt will have some form of testing in place to ensure that the code is doing what it’s supposed to do.
If you’re tasked with debugging or adding a particular feature, you may need to also modify the test to check on the functionality of the pieces of code you are working on. Testing can be tedious and detail-oriented, but it’s an important part of working with code written by someone else.
4. Follow the style guide
While you may have your own style when writing code, the larger codebase you’re working on will have a style guide that needs to be followed. It’s important to understand the style guide and ensure that any additions you make to the code follow the same standards.
You’ll also want to know if there are any design standards in the code you’re working with, which could include colors, fonts, and spacing. Think about how crucial these elements are if you are working in front-end development. The interface and structure of a website will need to follow a set of rules or a style that’s been previously established.
5. Code like everyone’s watching
When you’re working with code written by another person, you want to add to the codebase by considering your teammates. If someone was to pick up the code you wrote, would it be easy for them to understand and add to it? You want to make your contribution as clean and easy to modify as possible.
6. Make use of good patterns
Good patterns naturally evolve in the world of programming to form a set of best practices. Some developers will call these design patterns. Writing code this way means:
- There’s no repetition.
- The code is extensible.
- It’s structured for maximum security.
- Efficiency is built in.
7. Ask questions
It’s easy to second-guess yourself and think you need to struggle through trying to figure out someone else’s code all on your own. It can be intimidating to start working with other developers, but they’ll be happy to answer your questions about the code they’ve written. “This is something I think new developers don’t do enough,” says Mike.
8. Stay positive
If the codebase you’re working with is legacy code, it can be easy to get bitter and frustrated toward the person that wrote the code in the first place. But your frustration won’t help to fix the problem. A positive attitude, on the other hand, could be useful.
If you approach the legacy code with the mindset that you can make a difference, you’ll make your workday much more enjoyable. It’s not the end of the world when code is written poorly and you need to take some extra time to understand it. Learning from others will make you more aware of how to write your programs to make them easy to modify.
9. Know the code
Before you jump in and start improving the code or adding your new feature, you must understand how the entire code works. You want to have a handle on how all the components work and fit together before you start moving things around and modifying the code.
10. Keep changes small
Resist the temptation to fix every single little problem you encounter in legacy code. The best practice is to not make any changes to the codebase unless it relates to the task you are currently implementing. If you start to change too many things, there may be unintended consequences that can quickly escalate.
How to get experience working with code written by someone else
Now that you have a handle on how to understand code written by another developer, it’s time to get some practice. The first way is to start working on an open-source project. For instance, there are many projects on GitHub that allow you to go in and make little corrections.
The second way to gain experience is by doing an internship or volunteering. Lastly, you can build things with your friends or fellow learners if you have an idea for an app or a website. Even if you’re just starting to learn how to code, you can gain experience by taking part in group projects and contributing to the online forums. If you’re enrolled in a Career Path on Codecademy, you can also find fellow learners to collaborate with in Career Path groups.