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?
当前回答
我总是说‘这就是我要做的’。我不会试图教训他们,告诉他们他们的代码是垃圾,而只是给他们一个不同的观点,希望能向他们展示一些明显更整洁的东西。
其他回答
如果你有一个松散的编码标准,能够指出这一点,或者表明你不能遵循代码,因为它不是正确的格式可能是值得的。
如果您没有编码格式,现在将是一个好时机。类似于这个问题的答案可能会有帮助:https://stackoverflow.com/questions/4121/team-coding-styles
开始进行代码评审或结对编程。
如果团队不愿意这么做,那就尝试每周设计回顾。每周开一个小时的会,讨论一段代码。如果人们看起来很有戒心,那就选择那些没有人在情感上依恋的旧代码,至少在一开始是这样。
正如@ jesere所说,关注代码,而不是编码员。
当你看到一些你认为应该不同的东西,但别人不这么看的时候,那就开始问一些导致缺陷的问题,而不是指出它们。例如:
Globals:你认为我们还会想要更多这样的东西吗?你认为我们会想要控制它的使用权吗?
可变状态:你认为我们想要从另一个线程操纵它吗?
我还发现关注自己的局限性很有帮助,这可以帮助人们放松。例如:
长功能:我的大脑不够大,不能一次容纳所有这些。我们怎样才能做出更小的我能处理的东西呢?
坏名声:在阅读清晰的代码时,我很容易感到困惑;当名字被误导时,我就没有希望了。
最终,你的目标不是教会你的团队如何更好地编码。而是在你的团队中建立一种学习的文化。每个人都向他人寻求帮助,成为更好的程序员。
介绍代码标准的思想。关于代码标准最重要的事情是它提出了代码库的一致性(理想情况下,所有的代码都应该看起来像由一个人一次编写的),这将导致更容易理解和可维护的代码。
耐心再怎么强调都不为过。我见过这种完全事与愿违的事情,主要是因为有人希望现在就发生变化。相当多的环境需要进化的好处,而不是革命。今天强行改变,可能会给所有人带来一个非常不愉快的环境。
接受是关键。你的方法需要考虑到你所处的环境。
听起来你所处的环境有很多“个性”。所以…我不建议使用一套编码标准。你会发现你想把这个“有趣”的项目变成一个高度结构化的工作项目(哦,太好了,接下来是什么……功能文件?)相反,正如其他人所说,你必须在一定程度上处理它。
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).
耐心。进化,而不是革命。
祝你好运。
这完全取决于你写作的文化。在一个自由软件项目中,你告诉他们他们写的代码不好,并给出积极的建议、改进方法和反馈。你也可以给他们的代码发送一个补丁。
一封友好的电子邮件也不会有什么坏处。
推荐文章
- 你如何告诉别人他们写的代码不好?
- main()中的Return语句vs exit()
- 对于一个布尔字段,它的getter/setter的命名约定是什么?
- 为什么CSS选择器/ HTML属性首选破折号?
- 在c++中使用"super
- 在PHP中使用getter和setter而不是函数或简单的公共字段有什么优点?
- foo到底是什么意思?
- 什么时候使用“this”关键字?
- 对Python ' import x '和' from x import y '语句排序的正确方法是什么?
- 在Python中创建空列表
- 将c++定义放在头文件中是一个好习惯吗?
- 使用“for”循环遍历c++ Vector
- 在条件表达式中检查可空bool值的最佳方法(if…)
- 如何在JavaScript中设置多个CSS样式?
- 字典和默认值