code-duplication

Duplicate some parts of XML without rewriting them

♀尐吖头ヾ 提交于 2019-12-02 05:53:52
问题 I have an XML file with duplicate parts such as: <argument name="create"> <argument name="user" type="text"></argument> <argument name="password" type="password"></argument> (and so on) </argument> <argument name="update"> <argument name="user" type="text"></argument> <argument name="password" type="password"></argument> (and so on) </argument> I would like to have the part between create and update declared once then append it between create and update with a one-liner. This would save me a

How to avoid code duplication of different structs with semantically equal fields/properties?

China☆狼群 提交于 2019-12-02 01:55:30
问题 Given these two structs: pub struct RectangleRenderer { canvas: Canvas, origin: Point, shape: Rectangle, } pub struct CircleRenderer { canvas: Canvas, center: Point, shape: Circle, } As I come from Java, I would extract a base class ShapeRenderer out of those and apply the fields canvas and origin into that while the specific types will keep their field called shape . What's the best practice in Rust for this situation since traits only act similar to interfaces and therefore do not allow

How to avoid code duplication of different structs with semantically equal fields/properties?

[亡魂溺海] 提交于 2019-12-02 00:05:17
Given these two structs: pub struct RectangleRenderer { canvas: Canvas, origin: Point, shape: Rectangle, } pub struct CircleRenderer { canvas: Canvas, center: Point, shape: Circle, } As I come from Java, I would extract a base class ShapeRenderer out of those and apply the fields canvas and origin into that while the specific types will keep their field called shape . What's the best practice in Rust for this situation since traits only act similar to interfaces and therefore do not allow properties/fields? This looks like a perfect case for generics . You can make a single struct like this:

Duplicate some parts of XML without rewriting them

无人久伴 提交于 2019-12-01 22:54:15
I have an XML file with duplicate parts such as: <argument name="create"> <argument name="user" type="text"></argument> <argument name="password" type="password"></argument> (and so on) </argument> <argument name="update"> <argument name="user" type="text"></argument> <argument name="password" type="password"></argument> (and so on) </argument> I would like to have the part between create and update declared once then append it between create and update with a one-liner. This would save me a lot of lines. Any way to do that in XML? imhotap You can use SGML/XML"entities" for that, which can

Detect duplicate code in Visual Studio 2010

佐手、 提交于 2019-12-01 16:04:24
Clone Detective was a great tool for finding duplicate code in VS 2008. Are there any tools for finding duplicate code which integrate into VS 2010? *Clone Detective doesn't look like its being actively developed 1 2 . (You don't seem to have gotten any answers after a couple of weeks... hints there aren't any that do exactly what you want). Our CloneDR is a tool that detects cloned code for C# 4.0 and modern Microsoft C++ dialects, parsing to abstract syntax trees to drive the clone detection process. This produces, IMHO, a higher-quality result than the token-based scheme used by ConQAT

Detect duplicate code in Visual Studio 2010

僤鯓⒐⒋嵵緔 提交于 2019-12-01 15:23:34
问题 Clone Detective was a great tool for finding duplicate code in VS 2008. Are there any tools for finding duplicate code which integrate into VS 2010? *Clone Detective doesn't look like its being actively developed 1 2. 回答1: (You don't seem to have gotten any answers after a couple of weeks... hints there aren't any that do exactly what you want). Our CloneDR is a tool that detects cloned code for C# 4.0 and modern Microsoft C++ dialects, parsing to abstract syntax trees to drive the clone

Code duplication between typedefs and explicit instantiations

白昼怎懂夜的黑 提交于 2019-11-30 15:17:32
tree.h template<typename Functor, char Operator> class binary_operation : public node { // ... unimportant details ... unsigned evaluate() const; void print(std::ostream& os) const; }; typedef binary_operation<std::plus<unsigned>, '+'> addition; typedef binary_operation<std::multiplies<unsigned>, '*'> multiplication; // ... tree.cpp template<typename Functor, char Operator> unsigned binary_operation<Functor, Operator>::evaluate() const { // ... unimportant details ... } template<typename Functor, char Operator> void binary_operation<Functor, Operator>::print(std::ostream& os) const { // ...

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

倖福魔咒の 提交于 2019-11-30 03:05:50
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 ... ). msalib Yes, try the Copy Paste Detector . http://patterninsight.com/products/cp-miner.php Related paper - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.123.113 Our CloneDR is a tool for finding exact and near-miss blocks of code constructed by copy and paste activities. It can handle systems of millions of

Code duplication between typedefs and explicit instantiations

房东的猫 提交于 2019-11-29 21:16:41
问题 tree.h template<typename Functor, char Operator> class binary_operation : public node { // ... unimportant details ... unsigned evaluate() const; void print(std::ostream& os) const; }; typedef binary_operation<std::plus<unsigned>, '+'> addition; typedef binary_operation<std::multiplies<unsigned>, '*'> multiplication; // ... tree.cpp template<typename Functor, char Operator> unsigned binary_operation<Functor, Operator>::evaluate() const { // ... unimportant details ... } template<typename

How much duplicated code do you tolerate? [closed]

谁说我不能喝 提交于 2019-11-29 21:15:21
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 refactor the code, he argued that the code is simpler to understand that way. After reading the code again, I have to agree extracting the duplicated logic would hurt readability a little. I know DRY is guideline, not an absolute rule. But in general, are you willing to hurt readability in the name of DRY? Nick Dandoulakis Refactoring: Improving the Design of Existing Code The Rule of Three The first time you do something, you just do it. The second time you do