Is there a way to measure duplicate code? [closed]
Have a look Simian, you can use it for Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files. Also, a similar question here.
Have a look Simian, you can use it for Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files. Also, a similar question here.
Ask him what will he do when he finds a bug in his code. How many places will he now need to fix it in? You can also show him the answers to this question (Why is “copy and paste” of code dangerous?).
I tend to use a “super type” like long or double if I still want a primitive. The performance is usually very close and it avoids creating lots of variations. BTW: registers in a 64-bit JVM will all be 64-bit anyway.
As an alternative to calling an initialization method from all constructors (which prevents you from using readonly fields) or factory methods (which introduce additional complexity when you have derived classes), you can use a parameter object: int a, b, c; public Constructor() : this(new ConstructorParameters()) { } public Constructor(int x, int y) : this(new ConstructorParameters(x, … Read more
Congratulations, you just rediscovered anamorphisms! Here’s your code, rephrased so that it works with the recursion-schemes package. Alas, it’s not shorter, since we need some boilerplate to make the machinery work. (There might be some automagic way to avoid the boilerplate, e.g. using generics. I simply do not know.) Below, your recurseAfter is replaced with … Read more
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 something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor. Three strikes and you refactor. Coders … Read more
This works for me. You have to set it on both classes/methods if you want to suppress the warning both places. @SuppressWarnings(“Duplicates”) private void myDuplicatedMethod() { … }
Simian detects duplicate code in C++ projects. Update: Also works with Java, C#, C, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files
Readability is more important for tests. If a test fails, you want the problem to be obvious. The developer shouldn’t have to wade through a lot of heavily factored test code to determine exactly what failed. You don’t want your test code to become so complex that you need to write unit-test-tests. However, eliminating duplication … Read more
For a detailed explanation, please see the heading “Avoid Duplication in const and Non-const Member Function,” on p. 23, in Item 3 “Use const whenever possible,” in Effective C++, 3d ed by Scott Meyers, ISBN-13: 9780321334879. Here’s Meyers’ solution (simplified): struct C { const char & get() const { return c; } char & get() … Read more