[009] DS的Code Review该怎么做?这15条建议可以了解一下

其实我个人也是十分推荐Code Review的,也是十分享受这个过程,这篇文章,讲诉了我们该如何开展Code Review,以及我们在当中应当关注的事情,还有我们可以从中获得的好处有哪些,是一篇比较全面概括Code Review的文章,很赞!

When reviewing code or working through problems, sometimes more than one person looking at the code can be a huge benefit; hence, why I love code reviews! Code reviews are beneficial regardless of the type of code you are writing. A code review is when at least one developer or data scientist looks over your code and review the work. Common topics discussed are logic errors, review of code requirements, testing, and conformity to a coding style guide. As Dan Radigan puts it in his article on Why code reviews matter (and actually save time!):

No one is the only person who knows a specific part of the code base. Simply put, code reviews help facilitate knowledge sharing across the code base and across the team.

This past year I have hosted weekly code review meetings where at least three to five developers and data scientists meet to discuss any open pull requests. As I began to host these meetings, I have learned some valuable lessons on why code reviews are essential to any team. Code reviews allow for exposure to new ideas and technologies, feedback on code development and progression, and offer a general forum to discuss any issues or questions one may have.

Exposure to New Ideas and Technologies

The main reason I have found code review meetings beneficial on a data science team is the exposure to new ideas and technologies. Being apart of a large team means a data scientist may not be aware of everything people are developing. Having the opportunity to sit in on code reviews allows them to see different projects people have been working on, understand how they wrote the code, and even ask questions. There is so much you can learn from talking with others about your code!

1. Ask questions! (提出问题!)
If you are reviewing someone's code and do not understand something or are curious about why they did something a particular way, ask. Asking questions is especially important with data science projects. It would be best if you cleared up assumptions made on the data or implementation.

2. Find ways to clean up and condense code. (找到可以清理和压缩代码的方法)
If you communicate with different developers often on ways they perform similar actions, you can develop a class or set of functions that will perform those actions. These discussions may spark new ideas for how to condense and clean the different implementations up.

3. Discuss the next steps and action items. (讨论后续步骤)
Discussing the next steps or actions may seem like an odd thing to bring up in a code review, but it can be very beneficial. Having a discussion with others on what is next for the work can spark conversations on what they envision for the future. They may have other use-cases for you to consider or ask to work on a particular part of the project.

4. Explain the use of any new libraries or technologies in the code. (介绍与解释代码中所有新库或者新技术的使用)
With over 30+ developers and data scientists, someone may often begin to use a new technology or open-source library. Code reviews are an excellent place to start a conversation to ask for a brief overview. You can always schedule a follow-up to learn more or do a deep-dive on the work. I have found these discussions beneficial as you learn who has experience with what libraries and technologies, so if you run into questions, you know who to ask.

5. Understand different ways to do the same thing. (了解做一件事情的不同方法)
For example, you want to filter a dataframe. There are various ways you can filter data before performing any analyses; getting feedback during your code review will allow you to discuss different ways to perform a specific action. A discussion like this can come in handy if your runtime is slow and you are looking to optimize your code. There may be more efficient ways to do the same task.

Feedback on Code Development and Progression

As I host these meetings, I share my screen with the developer’s code, and we walk through the work line by line. For our team, it is common that a project may require multiple pull requests in one or more repositories while it is being worked on. Therefore, these discussions allow us to discuss if the implementation of code is going positively or not. Questions you can ask during the code review on code development and progression are:

6. Talk about code architecture. (讨论代码架构)
Why did you decide to architect the code in this manner? Have you considered another way? If you are recommending something, providing an example can be very beneficial to someone.

7. Review the nested functions or nested loops in the code. (查看代码中的嵌套函数或循环)
Have you considered restructuring your code to make it more readable and more reusable? How could you go about cleaning this up?

8. Look over kwargs and variables. (查看kearg和变量)
In what ways have you utilized user-provided arguments, variables, and other inputs? Do these need to be cleaned up in any way? If you have any recommendations in this area, let your colleague know. Again, examples can be very beneficial to explain other ways of doing things.

9. Evaluate the output of the code. (评估代码的输出)
In a code review, we commonly will share the output of code in our reviews, especially when the outcomes are reports or visualizations. This output is shared to get feedback on any updates the visuals will need or spot bugs in the output after rendering. Implementing reviews in this manner has reduced errors in production.

10. Spot logic errors or bugs. (发现逻辑错误bug)
Hopefully, by the time you have reached a code review, the bugs have been weeded out, but you never know. Walking through code, look for places that you may need to verify the user input, add try-catch statements, or throw exceptions that were not considered. Also, be on the lookout for logic errors. These are the hardest to catch as the output may be slightly off but not easily noticed.

As you read through these questions, you may notice I am a huge advocate for providing examples. People will be at different levels of coding experience. Whether you are working with senior developers and data scientists or someone who is brand new, an example can be very beneficial to illustrate your point.

Forum to Discuss

Lastly, code reviews, especially in a meeting format, give developers and data scientists a great forum to facilitate open discussions. Some code reviews I participate in are not formal, meaning they are not linked to an open pull request. These informal code reviews are meetings in which a developer or data scientist invites one or two people to a meeting to show them what they have been doing and discuss the code. These meetings happen well before the formal code review sessions and are useful when making decisions on implementation or working through a bug.

11. Be open about what you don't know. (对未知的事物保持开放)
Not every developer or data scientist will know everything. Be honest with your colleagues about what you don't know and facilitate a discussion around it. Informal code reviews are great opportunities to learn more. You can screen-share your code and walk through it with others.

12. Ask for recommendations or advice. (寻求建议或意见)
If you are trying to decide how you will write the code or what method is best to move forward with, open a discussion with your colleagues. These discussions may bring about things you did not consider, which will help you decide. These discussions are especially great to have if the outcome could impact the code architecture.

13. Take away action items from your conversations. (不要在讨论中直接改代码,把时间留给下面的讨论)
Sometimes your code will look great, and you will have no next steps. Most times, you will have comments to review and code to update. Discuss your next steps. Make sure you fully understand what you need to work on, as this is your time to gather those notes before moving forward on your work.

14. Share your bugs! (分享错误)
If you are stuck too long on a bug, open a call with at least one other person and ask for help. Asking for someone to review your code to aid in looking at the bug can speed up finding a resolution, giving you more time back to continue development. If I am taking more than a couple of hours, I call backup.

15. Whiteboard ideas with one another and facilitate a discussion to generate action items. (互相交流思想,并促进讨论以产生行动)
During these informal code reviews, you can meet with colleagues to show them concepts you are toying with. Whiteboard out an idea, work through small examples and discuss areas for improvement. These types of discussions can lead to some great collaboration and generate new ideas to investigate.

Final Thoughts

Code reviews can be a beneficial tool to allow multiple developers or data scientists to look over code someone is developing. You can use these code reviews to be introduced to new libraries and technologies, get feedback on your code development and progression, or have a forum for open discussions on different aspects of your code before a formal pull request is opened. Use code reviews to your advantage as a tool for learning and personal development.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值