Дублирование кода | Participants
|
- Statistics
- Participants
- Translate into Russian
- Translation result
- 86% translated in draft. Almost done, let's finish it!
If you do not want to register an account, you can sign in with OpenID.
Duplicate code | ||
{{Mergeto | Don't repeat yourself |discuss=Talk:Don't repeat yourself#Duplicate code |date=February 2009 }} | {{Mergeto | Don't repeat yourself |discuss=Talk:Don't repeat yourself#Duplicate code |date=February 2009 }} | |
'''Duplicate code''' is a [[computer programming]] term for a sequence of [[source code]] that occurs more than once, either within a program or across different programs owned or maintained by the same entity. Duplicate code is generally considered [[Code smell|undesirable]] for a number of reasons.<ref>{{cite web|url=http://www.informit.com/articles/article.aspx?p=457502&seqNum=5|title=The Bad Code Spotter's Guide|publisher=InformIT.com|accessdate=2008-06-06|first=Diomidis|last=Spinellis}}</ref> A minimum requirement is usually applied to the quantity of code that must appear in a sequence for it to be considered duplicate rather than coincidentally similar. Sequences of duplicate code are sometimes known as '''clones'''. | '''Дублирование кода''' - термин из [[Программирование|программирования]], под которым понимается что некоторые участки [[Исходный_код|исходного кода]] могут встречаться более чем однажды, как внутри одной, так и в нескольких програмных сущностях. Дублирование делает код [[Code smell|дурно пахнущим]].<ref>{{cite web|url=http://www.informit.com/articles/article.aspx?p=457502&seqNum=5|title=The Bad Code Spotter's Guide|publisher=InformIT.com|accessdate=2008-06-06|first=Diomidis|last=Spinellis}}</ref> В первую очередь потому, что увеличивается его длинна; именно из-за дублирования а не из-за совпадений. Последовательность дубликатов иногда называют '''клоны'''. | |
The following are some of the ways in which two code sequences can be duplicates of each other: | Вот список причин по которым два куска кода могут считаться дубликатами: | |
* character-for-character identical | ||
* character-for-character identical with white space characters and comments being ignored | * посимвольное совпадение, с игнорированием пробельных символов и коментариев | |
* token-for-token identical | ||
* token-for-token identical with occasional variation (i.e., insertion/deletion/modification of tokens) | ||
* functionally identical | ||
==How duplicates are created== | ||
There are a number of reasons why duplicate code may be created, including: | Вот ряд причин по которым дубликаты кода могут быть созданы: | |
*[[Copy and paste programming]], in which a section of code is copied "because it works". In most cases this operation involves slight modifications in the cloned code such as renaming variables or inserting/deleting code. | * Программирование [[Copy and paste programming|копированием-вставками]], при котором участки кода копируются просто потому, что "это работает". В большинстве случаев такая операция требует небольших изменений переносимого кода, например переименования переменных или добавление/удаление некоторых участков. | |
*Functionality that is very similar to that in another part of a program is required and a developer independently writes code that is very similar to what exists elsewhere. | * Требуется функциональность которая очень похожа на уже существующую в другой части программы, и программист пишет код очень близкий к тому, который уже существует. | |
*[[Plagiarism]], where code is simply copied without permission or attribution. | *[[Плагиат]], когда код просто копируется без соблюдения прав или каких-либо условий. | |
==Problems associated with duplicate code== | ||
Code duplication is generally considered a mark of poor or lazy programming style. Good coding style is generally associated with [[code reuse]]. It may be slightly faster to develop by duplicating code, because the developer need not concern himself with how the code is already used or how it may be used in the future. The difficulty is that original development is only a small fraction of a product's life cycle, and with code duplication the maintenance costs are much higher. Some of the specific problems include: | Дублирование кода является признаком низкого или ленивого стиля программирования. Хороший стиль программирования обычно основан на [[Повторное_использование_кода|повторном использовании кода]]. Может казаться, что использование дубликатов позволит несколько ускорить процесс создания программы, так как программисту не нужно будет вдумываться над тем, как код уже используется и как он может использоваться в дальнейшем. Однако проблема заключается в том, что написание кода это лишь скромная часть жизненного цикла продукта, и дальнейшее сопровождение кода с дубликатами будет слишком осложнено. Вот несколько проблем к которым приводит дублирование кода: |
