问题描述
关于Stackoverflow有几个问题,关于是否有什么最佳的编码约定/样式正在进行研究。这不是这个问题的意思。这个问题是关于是否有任何研究来研究拥有整个组织范围的编码约定和样式是否有任何优势,生产率的提高或其他积极的副作用。
我对此有自己的看法,基本上说,制定这样的标准有很多好处。坦白说,只要能够在所有可能使用的代码中保持一致,我就不会在乎我需要使用哪种样式。
我只是想知道是否有任何研究支持我的观点或与之相矛盾。
多项研究表明,严格遵守一致的视觉样式有助于经验丰富的程序员在内存中保留更多本地问题,而不必记住问题的各个要素。
一致的编码样式辅助
它与人类记忆的工作方式有关。它称为 chunking 。例如,与不熟悉游戏的人相比,象棋大师在记忆棋位置方面要好得多。但这仅在碎片以自然位置出现时才发生。在正常游戏中会发生这种情况。如果您将棋子放置在任意位置,则在记忆棋盘位置时,象棋大师 没有比没有象棋的人更好的。
相同的概念适用于程序员。当编码风格是一致的时,编码构造看起来是自然的。对程序员来说,代码的大部分更容易被吸收。我们的短期记忆具有大约七个正负两的容量。因此,熟悉的块越大,我们的思想就可以在内存中活跃地保留更多的原始数据()。
面对随机格式的代码,程序员不得不花费更多的精力来手动解析出问题所在的各个方面正在努力。这就失去了将更大的问题保留在内存中进行处理的能力。这也意味着,要花更长的时间才能达到程序员有效解决当前问题的水平。
流程时间
您曾经发现吗当您继续进行处理时,问题似乎很明显,但随后您似乎丢失了信息。当您稍后再回到问题上时;即打破您的流动时间?流时间在(必须供所有程序员阅读)。流程时间是程序员完成大部分工作的时间,只有在您长时间不间断地处理问题时才能实现流程时间。那是因为程序员需要一定的时间才能将足够多的问题吸收到认知记忆中,才能有效地解决该问题。格式正确的代码有助于我们进行视觉图像处理,这意味着程序员可以更快地达到流程时间。
我已经在多家软件公司编写了编码标准。不幸的是,有许多程序员认为编码标准只是断言不必要地控制其行为的一种手段。一种创造性的审查制度。实话实说,实际标准到底有多重要。这样做的价值在于使团队中的每个人保持一致,即使这意味着在做我自己的方式或做你自己的方式之间经常做出任意决定。 p>
以下是我上面提到的一些参考:
- <-必须阅读
There are a couple of questions on Stackoverflow on whether there is any research or studies into what is the best coding convention/style. That's not what this question is about. This question is about whether there are any studies that research whether there are any advantages, productivity gains or other positive side effects to having an organization-wide coding convention and style.
I have my own opinions on this, which is basically that there is huge benefits to having such standards in place. Honestly, I couldn't care less what style I am required to use as long as it is consistent in all the code I might have to work with.
I just want to know if there are any studies that back my opinions or contradict them.
There have been several studies showing that a strict adherence to a consistent visual style helps experienced programmers keep more of the local problem in memory without having to memorize the individual elements of the problem.
Consistent Coding Style Aids Chunking
It has to do with how the human memory works. It is called chunking. For example, it is a well-studied phenomenon that chess masters are much better at memorizing chess positions than people who are not familiar with the game. But that is only if the pieces occur in "natural positions" that can occur in a normal game. If you place the chess pieces in random positions, chess masters are no better off than non-chess players at memorizing board positions.
The same concept applies to programmers. When coding styles are consistent, the coding constructs appear "natural" to the programmer and larger portions of the code are easier to assimilate. Our short term memory has a capacity of about "seven plus-or-minus two" chunks so, the larger those familiar chunks are, the more raw data our mind can actively hold in memory (George Miller).
When faced with randomly-formatted code, programmers have to expend addition mental energy to manually parse out the individual pieces of the problem they are working on. That takes away from the ability to hold larger pieces of the problem in memory to work on it. It also means that it takes longer to reach a point where the programmer is productively solving the problem at hand.
Flow Time
Have you ever found that a problem seems so clear while you continue to work on it but then you seem to "lose the information" when you come back to the problem later; i.e. break your flow time? Flow time is well-documented in Peopleware (a must read for all programmers). Flow time is when programmers get a large majority of work done and is only achieved when you are working on a problem for an extended, uninterupted period of time. That is because it takes a certain period of time for a programmer to assimilate enough of the problem into cognitive memory to effectively work on the problem. Well-formatted code helps our visual image processing which means programmers reach flow time much faster.
I have authored coding standards at several software companies. It is unfortunate how many programmers feel that coding standards are just a means of asserting unneeded control over how they do things; a form of creative censorship. Truth be told, it rarely matters what the actual standards are. The value is in getting everyone on a team to be consistent, even if it means making an often-arbitrary decision between doing it my way or doing it your way.
Here are a few reference I mentioned above:
- Peopleware: Productive Projects and Teams <-- A Must Read
- Empirical Studies of Programmers - Cognitive Analysis of a Code Inspection
- The Chess Memory
- A computer model of chess memory
- Chunking (psychology)
这篇关于具有标准编码样式的优势的研究的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!