From time to time, I find myself copying a bit of code and modifying the copied version. I know very well that having two copies of the same code is a very bad idea, but those pieces of code are small and have significant differences.
The problem is, when modifying the copy, I sometimes forget some piece of the original, that shouldn't be there. So for example I first write (C# code, but that's not important here):
if (DateFrom != null) query = query.Where(x => x.Date >= DateFrom.Value);
then I copy-paste it and modify into the following:
if (DateTo != null) query = query.Where(x => x.Date < DateFrom.Value);
which isn't correct, because there should be
DateTo on the second line instead of
What would you suggest to help avoiding this kind of bug?