Pre-apprenticeship

Wednesday Week 7

Code Review

Why review code?

Reading other people’s code is a good way to learn.

Not only do you gain insight into how other people solve a problem, you also see what makes code readable and understandable.

Who reviews what?

Each team reviews one other team’s project.

Make sure you share a link to your GitHub repo on Discord when code review begins.

Reviewing

  • Open the repo on GitHub and scan the readme.
  • If the project is deployed online open it and play around.
  • Does the project meet the user stories for that week?
  • Does it demonstrate the learning outcomes for that week?
  • Can you see any obvious bugs or areas to improve?

Clone the repo and follow the instructions to run it locally.

Does everything work as expected? Often the different environment will highlight issues that the team missed.

Open the project in your editor.

Does the file structure make sense? Can you you follow the different paths the code might take? Do variables and functions have clear and descriptive names?

Raise issues

Your issue title should clearly summarise the content.

If you’re commenting on a specific section of code you can embed it in the issue.

Link to relevant documentation if you’re suggesting something they may not have seen before.

Try to make sure your issues are clear and actionable.

Don’t focus on small subjective preferences.

Highlight code that confused you, or that has the potential to break unexpectedly.

Don’t feel like you have to look at all the code that’s written. Take your time exploring fewer things in more detail.

Review etiquette

Phrase your issues in an open-minded way: use questions and seek to understand.

Don’t assume you know better–you’re missing the original context and can’t know exactly why they wrote the code in the way they did.

If you think you know a better way of solving a problem, phrase the issue as a question:

Would you consider using this here instead of that because of xyz reason…?

Issues don’t all have to be negative: if you spot something particularly clever or elegant say so!

It’s nice to get occasional compliments as well as suggestion for improvement.

When receiving reviews try to remember that the reviewer has your best interests at heart. They want to help you become a better developer, so assume they have good intent.

You are not your code.

Code Review pairs

Pair One Reviews Pair Two
Anna, Mohamed Cemal, Alex
Adriana, Barbara Danilo, Sasha
Elena, Michael Ji, Saira

Promises

This week, we’ll build up our understanding of functions, callbacks, asynchronous JavaScript and promises.

Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function.

JavaScript is single threaded. This means only one piece of code can run at a time.

Promises allow us to chain callbacks which resolve only after the previous one has.

Workshop

Functions, callbacks, async