How do you tell someone they're writing bad co

2019-01-20 20:57发布

I've been working with a small group of people on a coding project for fun. It's an organized and fairly cohesive group. The people I work with all have various skill sets related to programming, but some of them use older or outright wrong methods, such as excessive global variables, poor naming conventions, and other things. While things work, the implementation is poor. What's a good way to politely ask or introduce them to use better methodology, without it coming across as questioning (or insulting) their experience and/or education?

30条回答
神经病院院长
2楼-- · 2019-01-20 21:33

Have code reviews, and start by reviewing YOUR code.

It will put people at ease with the whole code review process because you are beginning the process by reviewing your own code instead of theirs. Starting off with your code will also give them good examples of how to do things.

查看更多
疯言疯语
3楼-- · 2019-01-20 21:34

If possible, make sure they understand that you're critizising their code, not them personally.

查看更多
何必那么认真
4楼-- · 2019-01-20 21:34

I do love code, and never had any course in my live about anything related to informatics I started very bad and started to learn from examples, but what I always remember and kept in my mind since I read the "Gang Of Four" book was:

"Everyone can write code that is understood by a machine, but not all can write code that is understood by a human being"

with this in mind, there is a lot to be done in the code ;)

查看更多
神经病院院长
5楼-- · 2019-01-20 21:36

Suggest a better alternative in a non-confrontational way.

"Hey, I think this way will work too. What do you guys think?" [Gesture to obviously better code on your screen]

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-20 21:37

Introduce the idea of a code standard. The most important thing about a code standard is that it proposes the idea of consistency in the code base (ideally, all of the code should look like it was written by one person in one sitting) which will lead to more understandable and maintainable code.

查看更多
beautiful°
7楼-- · 2019-01-20 21:38

A lot of the answers here relate to code formatting which these days is not particularly relevant, as most IDEs will reformat your code in the style you choose. What really matters is how the code works, and the poster is right to look at global variables, copy & paste code, and my pet peeve, naming conventions. There is such a thing as bad code and it has little to do with format.

The good part is that most of it is bad for a very good reason, and these reasons are generally quantifiable and explainable. So, in a non-confrontational way, explain the reasons. In many cases, you can even give the writer scenarios where the problems become obvious.

查看更多
登录 后发表回答