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:44

The code standard idea is a good one.

But consider not saying anything, especially since it is for fun, with, presumably, people you are friends with. It's just code...

查看更多
beautiful°
3楼-- · 2019-01-20 21:45

First, I'd be careful not to judge too quickly. It's easy to dismiss some code as bad, when there might be good reasons why it's so (eg: working with legacy code with weird conventions). But let's assume for the moment that they're really bad.

You could suggest establishing a coding standard, based on the team's input. But you really need to take their opinions into account then, not just impose your vision of what good code should be.

Another option is to bring technical books into the office (Code Complete, Effective C++, the Pragmatic Programmer...) and offer to lend it to others ("Hey, I'm finished with this, anyone would like to borrow it?")

查看更多
甜甜的少女心
4楼-- · 2019-01-20 21:45

By example. Show them the right way.

Take it slow. Don't thrash them for every little mistake right off the bat, just start with things that really matter.

查看更多
地球回转人心会变
5楼-- · 2019-01-20 21:46

Nobody likes to listen someone saying their work sucks, but any sane person would welcome mentoring and ways of avoiding unnecessary work.

One school of teaching even says that you should not point out mistakes, but focus what is done right. For instance, instead of pointing out incomprehensible code as bad, you should point out where their code is particularly easy to read. In the first case you are priming others to think and act like crappy programmers. In the later case you are priming for thinking like a skilled professional.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-20 21:46

Probably a bit late after the effect, but that's where an agreed coding standard is a good thing.

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

You have to explain why your way is better.

Explain why a function is better than cutting & pasting.

Explain why an array is better than $foo1, $foo2, $foo3.

Explain why global variables are dangerous, and that local variables will make life easier.

Simply whipping out a coding standard and saying "do this" is worthless because it doesn't explain to the programmer why it's a good thing.

查看更多
登录 后发表回答