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?


当前回答

并不是说我真的要在这个问题上增加那么多,但我必须同意,在处理这个问题时,最重要的两件事是解释你的推理,以及允许有问题的编码器解释他们的推理。坏代码不是凭空而来的(是的,“坏代码”当然是一个值得讨论的术语——我在某种程度上假设在这种情况下,您可以定义什么是好代码和坏代码)。

我发现提问式、教育性的方法对我的团队很有效。我从来不会在没有任何讨论或解释的情况下说“这样做”。

虽然你应该对这个问题有点敏感,但你不能粉饰这个问题。理想的情况是,您的团队正在考虑他们正在编写的代码,而不只是考虑代码在做什么,而是考虑它是如何编写的。

最后,我想补充一点,关于这个主题有很多值得探索的书籍——目前我最喜欢的是微软。net BCL团队的Brad Abrams和Krystof Kwalina(等人)所著的《框架设计指南》。它在讨论和解释所做的决定方面做得很出色,并展示了内部没有遵循指导方针的地方以及由此产生的后果。

其他回答

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

这完全取决于你写作的文化。在一个自由软件项目中,你告诉他们他们写的代码不好,并给出积极的建议、改进方法和反馈。你也可以给他们的代码发送一个补丁。

一封友好的电子邮件也不会有什么坏处。

耐心再怎么强调都不为过。我见过这种完全事与愿违的事情,主要是因为有人希望现在就发生变化。相当多的环境需要进化的好处,而不是革命。今天强行改变,可能会给所有人带来一个非常不愉快的环境。

接受是关键。你的方法需要考虑到你所处的环境。

听起来你所处的环境有很多“个性”。所以…我不建议使用一套编码标准。你会发现你想把这个“有趣”的项目变成一个高度结构化的工作项目(哦,太好了,接下来是什么……功能文件?)相反,正如其他人所说,你必须在一定程度上处理它。

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).

耐心。进化,而不是革命。

祝你好运。

糟糕的命名习惯:总是不可原谅的。

是的,不要总是认为你的方式更好……这可能很困难,但必须保持客观性。

I've had an experience with a coder that had such horrible naming of functions, the code was worse than unreadable. The functions lied about what they did, the code was nonsensical. And they were protective/resistant to having someone else change their code. when confronted very politely, they admitted it was poorly named, but wanted to retain their ownership of the code and would go back and fix it up "at a later date." This is in the past now, but how do you deal with a situation where they error is ACKNOWLEDGED, but then protected? This went on for a long time and I had no idea how to break through that barrier.

Global variables: I myself am not THAT fond of global variables, but I know a few otherwise excellent programmers that like them A LOT. So much so that I've come to believe they are not actually all that bad in many situations, as they allow for clarity, ease of debugging. (please don't flame/downvote me :) ) It comes down to, I've seen a lot of very good, effective, bug free code that used global variables (not put in by me!) and great deal of buggy, impossible to read/maintain/fix code that meticulously used proper patterns. Maybe there IS a place (though shrinking perhaps) for global variables? I'm considering rethinking my position based on evidence.

我穿上长袍,打开一罐苏格拉底方法。

苏格拉底方法以古希腊哲学家苏格拉底的名字命名,是一种哲学探究的形式,提问者探究他人立场的含义,以激发理性思考和阐明思想。这种辩证方法经常涉及到一种对立的讨论,在这种讨论中,一种观点的辩护与另一种观点相对抗;一个参与者可能会导致另一个人在某种程度上自相矛盾,加强询问者自己的观点。