I've started refactoring some legacy code recently and came across two functions for drawing a coordinate grid, the problem is that these functions differ only in orthogonal variables they treat, something like that
void DrawScaleX(HDC dc, int step, int x0, int x1, int y0, int y1)
{
for(int x = x0; x < x1; x += step)
{
...
A lot of the time I will have a Business object that has a property for a user index or a set of indexes for some data. When I display this object in a form or some other view I need the users full name or some of the other properties of the data. Usually I create another class myObjectView or something similar. What is the best way to h...
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 t...
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 are. It would also be nice...
What tool would you recommend for finding code duplicates in C# code?
...
In my question As a “mockist” TDD practitioner, should I mock other methods in the same class as the method under test?, Avdi answered "Personally I think that mocking on self is almost always a code smell. It's testing the implementation rather than the behavior." He may be right, but often I can't distinguish between the implementatio...
How fanatic are you about elimination of duplicate code?
Personally, whenever I see duplicate code, either in testing code or production, I tend to refactor the duplication away. The only exception I make are these:
Sometimes the reduction in duplication is very minimal, because the newly refactored method have too many parameters to ...
I wondered about the best way to implement a correct, flexible and fast Equals in C#, that can be used for practically any class and situation. I figured that a specialized Equals (taking an object of the actual class as parameter) is needed for performance. To avoid code duplication, the general Equals ought to call the specialized Equa...
I'm looking for the best approach to dealing with duplicate code in a legacy PHP project with about 150k lines of code.
Is this something best approached manually or are there standalone duplicate code detectors that will ease the pain?
...
I have being reading and tracking some questions on code reuse and I have this question:
Are there any tools to identify duplicate or similar code?
I have googled this a while ago and found nothing good.
...
I am trying to structure my code in such a way to reduce/avoid code duplication and I have encountered an interesting problem. Every time my code invokes a stored proc, I need to pass few variables that are common to the stored proc: such as username, domain, server_ip and client_ip. These all come from either HttpRequest object or a sys...
I have some research code that's a real rat's nest, with code duplication everywhere, and clearly needs to be refactored. However, the code base is evolving as I come up with new variations on the theme and fit them into the codebase. The reason I've put off refactoring so long is because I feel like the minute I spend a few days comin...
I've been wondering, at what point should I give up the convenience of a static data entry form with designer support for a dynamic UI which removes a lot of code duplication?
There seems to be a conflict in the programming world where people constantly try to remove code repetition to improve maintainability and yet when it comes to fo...
I have the following challenge, and I haven't found a good answer. I am using a Mocking framework (JMock in this case) to allow unit tests to be isolated from database code. I'm mocking the access to the classes that involve the database logic, and seperately testing the database classes using DBUnit.
The problem I'm having is that I'm ...
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,...
I'm currently working on two social networking sites that have a lot in common, yet are distinctively different. I find myself writing a lot of the same code for both (including UI), and was wondering if there is a best practice that will limit duplicating code.
One of the main problems is that these projects are very independent of ea...
We all agree that duplication is evil and should be avoid (Don't Repeat Yourself principle).
To ensure that, static analysis code should be used like Simian (Multi Language) or Clone Detective (Visual Studio add-in)
I just read Ayende's post about Kobe where he is saying that :
8.5% of Kobe is copy & pasted code. And that is with t...
I have the following couple of C pre-processor macros for creating test functions:
// Defines a test function in the active suite
#define test(name)\
void test_##name();\
SuiteAppender test_##name##_appender(TestSuite::active(), test_##name);\
void test_##name()
which is used like this:
test(TestName) {
// Test code h...
I'd like to find data deduplication algorithms, mostly to find duplicate files.
Looks like the first step is to identify the files with the same timestamps, sizes and file names. I can do the md5 chechsum on those files and compare. Addition to that it is possible to compare the contents of files. What else should I watch for?
...
When drawing the line between "relevant to programmers" and "plainly answerable", I typically lean toward the latter, but I'm really curious to hear what the community has to say about this. I have a feeling this should be CW (I've never created a CW topic), but I'll let someone with more SO experience make that call.
Summary:
Does "op...