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?


当前回答

与其让他们写代码,不如让他们维护代码。

除非他们不得不维护他们那堆冒着热气的意大利面,否则他们永远不会明白自己在编码方面有多糟糕。

其他回答

您可能想要关注坏代码的影响,而不是您对它的风格是好是坏的主观看法。

在Gerry Weinberg的书《计算机编程心理学》中有一些非常好的建议——他的“无我编程”的整个概念都是关于如何帮助人们接受对他们代码的批评,而不是对他们自己的批评。

你必须解释为什么你的方法更好。

解释为什么函数比剪切和粘贴更好。

解释为什么数组比$foo1, $foo2, $foo3更好。

解释为什么全局变量是危险的,而局部变量会让事情变得更容易。

简单地提出一个编码标准,然后说“这样做”是没有价值的,因为它没有向程序员解释为什么这是一件好事。

在他面前重构他的代码,并显示两个版本之间的差异。他肯定会喜欢的。

我不是我项目的首席开发人员,因此不能强加编码标准,但我发现糟糕的代码通常会迟早导致问题,当它发生时,我有一个更清晰的想法或解决方案。

通过在当时不插话,采取更自然的方法,我获得了领导更多的信任,他经常向我寻求想法,并让我参与项目的架构设计和部署策略。