code-duplication

How to detect code duplication during development? [closed]

微笑、不失礼 提交于 2019-12-17 15:08:44
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . We have a fairly large code base, 400K LOC of C++, and code duplication is something of a problem. Are there any tools which can effectively detect duplicated blocks of code? Ideally this would be something that developers could use during development rather than just run occasionally to see where the problems

Prevent duplicating application from USB memory

可紊 提交于 2019-12-13 07:05:15
问题 I wrote autorun application based on usb stick memory serial number. That means that the application will work only on specific registered serial number of the usb memory stick\device. I found out that advanced user could change the serial number of usb memory device and just copy my application from one usb stick memory device to another. I'm C++\C# developer, Is there any way i can prevent duplicating my application from one usb stick to another? 来源: https://stackoverflow.com/questions

Inhering type declarations in a hierarchy of templates

狂风中的少年 提交于 2019-12-13 06:27:19
问题 Consider this: template <typename T> struct A { using MyType1 = ...; using MyType2 = ...; using MyType3 = ...; using MyType4 = ...; using MyType5 = ...; ... }; template <typename T> struct B: A<T> { using MyType1 = typename A<T>::MyType1; using MyType2 = typename A<T>::MyType2; using MyType3 = typename A<T>::MyType3; using MyType4 = typename A<T>::MyType4; using MyType5 = typename A<T>::MyType5; ... }; template <typename T> struct C: A<T> { using MyType1 = typename A<T>::MyType1; using

manually enumerated data structs, need loops to generalize: perceptron algorithm

╄→尐↘猪︶ㄣ 提交于 2019-12-12 06:04:24
问题 My friend and I was having a lot of trouble trying to implement the perceptron algorithm, but then I found this tutorial, it goes through a java implementation and then has some example code. I substituted my own data structures for there ones in the tutorial, and it works! :) HOWEVER I made this substitution in the most simplistic possible way, manually enumerating my data structures. This works as a proof of concept, for my experimental "toy" data, but most certainly is not able to tackle

How do I get Simian to produce a nice HTML report I can email to everyone on the team?

你离开我真会死。 提交于 2019-12-11 15:43:03
问题 I am trying to discover how great our problem is with duplicate code, therefore I need to be able to mail a nice report (HTML, PDF, or word) to everyone on the team that lists all the duplicates that are found. How do I create such a report? (At this stage, I am just looking for a one-of ad hock solution to help with scoping the problem) (Our codebase is in VB.NET and I am running on Windows 7) 回答1: Personally I would wrote a (Perl|Insert your choice of language here) program that takes the

Deduplicating code in slightly different functions

百般思念 提交于 2019-12-11 13:16:58
问题 I have two very similar loops, and these two contain an inner loop that is very similar to a third loop (eh... :) ). Illustrated with code it looks close to this: # First function def fmeasure_kfold1(array, nfolds): ret = [] # Kfold1 and kfold2 both have this outer loop for train_index, test_index in KFold(len(array), nfolds): correlation = analyze(array[train_index]) for build in array[test_index]: # <- All functions have this loop # Retrieved tests is calculated inside the build loop in

php 5.3 avoid try/catch duplication nested within foreach loop (code sandwich)

你离开我真会死。 提交于 2019-12-11 04:43:13
问题 I have a class with methodA, which has existing structure as following function methodA() { $providers = $this->getFirstSetOfProviders(); foreach ($providers as $provider) { try { $this->method1($provider); } catch ( Exception $e ) { // exception handling } } $providers = $this->getSecondSetOfProviders(); foreach ($providers as $provider) { try { $this->method2($provider); } catch ( Exception $e ) { // exception handling } } } The content for the catch clauses are identical. Is there some way

template parameters, #define and code duplication

隐身守侯 提交于 2019-12-10 13:12:53
问题 I have a lot of code like this: #define WITH_FEATURE_X struct A { #ifdef WITH_FEATURE_X // ... declare some variables Y #endif void f (); }; void A::f () { // ... do something #ifdef WITH_FEATURE_X // ... do something and use Y #else // ... do something else #endif // ... do something } and I'd like to replace the #defines with template parameters: template < int WITH_FEATURE_X > // can be 0 or 1 struct A; But I don't want to duplicate almost the entire code of A::f() for A<0>::f() and A<1>:

Getting a template class specialization based on a Base policy work for all derived policies

只谈情不闲聊 提交于 2019-12-10 10:08:17
问题 I have policies that derive from a base policy. Some classes specialize for the derived policies while others specialize only for the base policy and can work with all derived policies. The problem I am running into is too much code-duplication (mainly constructors and some boiler plate code for the class itself). The code below may provide a better explanation of what I mean: struct BasePolicy {}; struct DerivedPolicy1 : public BasePolicy {}; struct DerivedPolicy2 : public BasePolicy {}; //.

To DRY or not to DRY? On avoiding code duplication and retaining cohesion

柔情痞子 提交于 2019-12-09 11:31:22
问题 I've got a question concerning code duplication and refactoring, hope it's not too general. Say you've got a rather small piece of code (~5 lines) which is a sequence of function invocations that is - not a very low level . This code is repeated in several places, so it would probably be a good idea to extract a method here. However, in this particular example, this new function would suffer from low cohesion (which manifests itself, among others, by having a hard time finding a good name for