code-duplication

Duplicated using directives in multiple files

跟風遠走 提交于 2019-11-29 14:12:32
I have got 5 C# files that have 20 using directives in common. I want to get rid of this code duplication, especially because these 20 using directives belong logically together. In C or C++ I would have created an extra header file containing these 20 include files. This extra header file acts as a layer then to include the 20 other files in one go. Unfortunately I don't know how to do this in C#. Any suggestions? You can't do this in C# since C# does not have a preprocessor, and the C# compiler, although it supports some syntax that looks like preprocessor syntax, is handled by the compiler

Do tools exist which automatically find copy-and-paste code? [closed]

青春壹個敷衍的年華 提交于 2019-11-29 00:10:18
问题 Are there tools out there which could automatically find copy-and-paste code among a set of files? I was thinking of writing a script for this, which would just search for equal strings, but such script would find mostly irrelevant equalities. (Such as private final static ... ). 回答1: Yes, try the Copy Paste Detector. 回答2: http://patterninsight.com/products/cp-miner.php Related paper - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.123.113 回答3: Our CloneDR is a tool for finding exact

How to find a similar code fragment?

喜欢而已 提交于 2019-11-28 18:21:46
Does anyone has some tool or some recommended practice how to find a piece of code which is similar to some other code? Often I write a function or a code fragment and I remember I have already written something like that before, and I would like to reuse previous implementation, however using plain text search does not reveal anything, as I did not use the variable names which would be exactly the same. Having similar code fragments leads to unnecessary code duplication, however with a large code base it is impossible to keep all code in memory. Are there any tools which would perform some

How much duplicated code do you tolerate? [closed]

人走茶凉 提交于 2019-11-28 16:59:45
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . In a recent code review I spotted a few lines of duplicated logic in a class (less than 15 lines). When I suggested that the author

Is duplicated code more tolerable in unit tests?

[亡魂溺海] 提交于 2019-11-28 02:56:28
I ruined several unit tests some time ago when I went through and refactored them to make them more DRY --the intent of each test was no longer clear. It seems there is a trade-off between tests' readability and maintainability. If I leave duplicated code in unit tests, they're more readable, but then if I change the SUT , I'll have to track down and change each copy of the duplicated code. Do you agree that this trade-off exists? If so, do you prefer your tests to be readable, or maintainable? Duplicated code is a smell in unit test code just as much as in other code. If you have duplicated

How do I remove code duplication between similar const and non-const member functions?

孤街浪徒 提交于 2019-11-25 22:29:44
问题 Let\'s say I have the following class X where I want to return access to an internal member: class Z { // details }; class X { std::vector<Z> vecZ; public: Z& Z(size_t index) { // massive amounts of code for validating index Z& ret = vecZ[index]; // even more code for determining that the Z instance // at index is *exactly* the right sort of Z (a process // which involves calculating leap years in which // religious holidays fall on Tuesdays for // the next thousand years or so) return ret; }