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

If you have even a loose standard of coding, being able to point to that, or indicating that you can't follow the code because it's not the correct format may be worthwhile.

If you don't have a coding format, now would be a good time to get one in place. Something like the answers to this question may be helpful: https://stackoverflow.com/questions/4121/team-coding-styles

查看更多
Lonely孤独者°
3楼-- · 2019-01-20 21:48

I can't emphasize patience enough. I've seen this exact sort of thing completely backfire mostly because someone wanted the changes to happen NOW. Quite a few environments need the benefits of evolution, not revolution. And by forcing change today, it can make for a very unhappy environment for all.

Buy-in is key. And your approach needs to take into account the environment you are in.

It sounds like you're in an environment that has a lot of "individuality" to it. So... I wouldn't suggest a set of coding standards. It will come across that you want to take this "fun" project and turn it into a highly structured work project (oh great, what's next... functional documents?). Instead, as someone else said, you'll have to deal with it to a certain extent.

Stay patient and work toward educating others in your direction. Start with the edges (points where your code interacts with others) and when interacting with their code try to take it as an opportunity to discuss the interface they've created and ask them if it would be okay with them if it was changed (by you or them). And fully explain why you want the change ("it will help deal with changing subsystem attributes better" or whatever). Don't nit-pick and try to change everything you see as being wrong. Once you interact with others on the edge, they should start to see how it would benefit them at the core of their code (and if you get enough momentum, go deeper and truly start to discuss modern techniques and the benefits of coding standards). If they still don't see it... maybe you'll need to deal with that within yourself (especially on a "fun" project).

Patience. Evolution, not revolution.

Good luck.

查看更多
家丑人穷心不美
4楼-- · 2019-01-20 21:49

People writing bad code is just a symptom of ignorance (which is different from being dumb). Here's some tips for dealing with those people.

  • Peoples own experience leaves a stronger impression than something you will say.
  • Some people are not passionate about the code they produce and will not listen to anything you say
  • Paired Programming can help share ideas but switch who's driving or they'll just be checking email on their phone
  • Don't drown them with too much, I've found even Continuous Integration needed to be explained a few times to some older devs
  • Get them excited again and they will want to learn. It could be something as simple as programming robots for a day
  • TRUST YOUR TEAM, coding standards and tools that check them at build time are often never read or annoying.
  • Remove Code Ownership, on some projects you will see code silos or ant hills where people say thats my code and you can't change it, this is very bad and you can use paired programming to remove this.
查看更多
贼婆χ
5楼-- · 2019-01-20 21:50

I'm not the lead developer on my project and therefore can't impose coding standards but I have found that bad code usually causes an issue sooner rather than later, and when it does i'm there with a cleaner idea or solution.

By not interjecting at the time and taking a more natural approach i've gained more trust with the lead and he often turns to me for ideas and includes me on the architectural design and deployment strategy used for the project.

查看更多
唯我独甜
6楼-- · 2019-01-20 21:50

Instead of having them write code, have them maintain their code.

Until they have to maintain their steaming pile of spaghetti, they will never understand how bad they are at coding.

查看更多
混吃等死
7楼-- · 2019-01-20 21:50

You probably want to focus on the impact of the bad code, rather than what might be dismissed as just your subjective opinion of whether it's good or bad style.

查看更多
登录 后发表回答