Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question already has an answer here:

Currently I'm working at a .NET project-based company. Our coding is not modularized, mostly we are copy/pasting old code that is needed on a new project and modify it.

I was trying to standardize and modularize some functions (Email Management Module, CMS Module & etc) by implementing a 3-tier architecture concept where each module would have its own independent module database. So that in the future all we'd need to do is just code a presentation layer, reuse the BLL layer, DAL Layer and database.

Is this system design reasonable? Will it work?

share|improve this question

marked as duplicate by Jim G., Martijn Pieters, Dynamic, World Engineer Mar 20 '13 at 21:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Yes, your solution works. It will only take the next five years to implement. // In my experience, trying to do things the right way under a management-mandated system based on the "do the quickest thing that works" principle ends up badly. –  Eduardo León Jul 13 '11 at 3:37
Danger Will Robinson, Danger Danger Danger: You used 'that' 4 letter word so common in software, particularly prevalent in failed projects. "Just". See if you can rewrite the sentence without trivializing the difficulty, or overstating the benefits of what you plan to do. –  mattnz Jul 13 '11 at 3:38
my English vocabulary and grammar is poor , can't write the proper sentence now. This my weakness , was trying reading english books to improve it . > < –  Johnny Tan Jul 13 '11 at 3:51
we knowing that was a huge workload , was planning each new project implement those concepts on 1 module , the rest using the old code . :-) –  Johnny Tan Jul 13 '11 at 3:59
thanks for the edit , Anna –  Johnny Tan Jul 13 '11 at 5:27

1 Answer 1

up vote 0 down vote accepted

In my opinion you should not change the code that works. Doing so can cause new bugs and wasting your development time for something that already there. You also need to make a regression testing so

Instead, why don't you implement your new framework for new modules only? By doing this way, at least you can make sure that all your new codes are reusable and neat.

On the code duplication, I believe you should implement something called Code Duplication Detection Tools. In java we have something called CPD(which is part of PMD) [link]. By doing this, you will be able to know which part of code are duplicated and able to make priority to refactor based on number of duplication. Just start refactor these duplication on your spare time and put them in some utility class so it's easier to be accessed from your old and new framework.

Try to find the .net version of CPD-PMD.

Note there is "Rule of Three" which states that

you are allowed to copy and paste the code once, but that when the same code is replicated three times, it should be extracted into a new procedure.

The rule was introduced by Martin Fowler. http://en.wikipedia.org/wiki/Rule_of_three_(programming)

share|improve this answer
IIRC, the Rule of Three was about copying between projects. Either way, I still wouldn't recommend copying at all in a project and always extract the functionality. Worse case, if I wasn't allowed to modify the existing code, would be to copy into a generic function for future use, and comment the old code to look at later. –  tylermac Jul 13 '11 at 14:12
No. Rule of Three is not about copying between projects. It's about when you should do the refactoring. This is the full explanation: "The first time you do something, you just do it. The second you do something similar, you wince at the duplication, but you do duplicate thing anyway. The third time you do something similar, you refactor." You can take a look at this reference : my.safaribooksonline.com/book/… –  Rudy Jul 13 '11 at 15:09
"In my opinion you should not change the code that works." What about refactoring? Of course, it's best to refactor when you need to implement a new feature. –  andho Feb 28 '13 at 9:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.