You’re sitting at home and realize the worlds gone black and white. Maybe there’s a cat prowling around the room, knocking over old case files, or a half empty bottle of cheap whiskey you didn’t finish from the night before. But they’re all distractions now. There’s a bug to be caught, or a branch of a project that needs refactored or hell, you just want to get your hand dirty. In any case, you’re about to start looking at someone else’s code.
But don’t worry, you’re a code detective and all the tools you need are at your fingertips.
Still, that knowledge didn’t feel particularly comforting when I started working with some slackers on our latest project: creating a new working path out of a pre-existing branch of a react-native-web project. So here’s a broad overview of what my approach to this project has been:
- Ask Questions:
- What’s my goal?
- How does the current code reflect those goals? i.e. What do I need to change or keep?
- If it’s a large scale application, then which files are relevant? Which can I ignore?
- Use Development Tools:
- The first thing I do with a web application I’m taking a stab at for the first time is watch the network calls while I go through the motions. Once I see the calls that are being made I can go back to the code and search for where the calls take place in the code and travel them like a tour map.
- But network activity typically isn’t enough. I console.log code to near obsession. It helps me understand the timeline of when things are happening in the code, and also gives me a more visual representation of the product.
- Check for plugins that can help.
- I’m making a lot of use of the React Developer Tools plugin for this project. It feels a bit unwieldy at times, but it’s such a benefit to be able to see which parent to child relationship of components is, and what renders as a result of what. This has taken me far in tracking down the files I really need to edit and what information they are privy to.
- Use your co-detectives!
- I’m so often working on my own I forget how important it is get feedback from other people. Just because you can normally solve a problem, doesn’t mean you’re going to solve it the best way possible, or in a timely manner. Open up and ask questions. If you don’t have a question about what you’re working on, ask your partner to explain their code to you. Who knows, maybe you’ll help them out and maybe you’ll find out something about your own code at the same time.
Those are the most important tools I find I have at my disposal, but this is by no means an exhaustive list. If you have your own means to deciphering someone else’s code, leave a comment below, I’m always looking for new ways to solve code!