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:你认为我们还会想要更多这样的东西吗?你认为我们会想要控制它的使用权吗?
可变状态:你认为我们想要从另一个线程操纵它吗?
我还发现关注自己的局限性很有帮助,这可以帮助人们放松。例如:
长功能:我的大脑不够大,不能一次容纳所有这些。我们怎样才能做出更小的我能处理的东西呢?
坏名声:在阅读清晰的代码时,我很容易感到困惑;当名字被误导时,我就没有希望了。
最终,你的目标不是教会你的团队如何更好地编码。而是在你的团队中建立一种学习的文化。每个人都向他人寻求帮助,成为更好的程序员。
糟糕的命名习惯:总是不可原谅的。
是的,不要总是认为你的方式更好……这可能很困难,但必须保持客观性。
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.
推荐文章
- 检查字符串是否包含字符串列表中的元素
- codestyle;把javadoc放在注释之前还是之后?
- .toArray(new MyClass[0]) or .toArray(new MyClass[myList.size()])?
- 你如何告诉别人他们写的代码不好?
- 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