What’s the single most important thing when writing code? And practical? To me, it’s the DRY, OAOO principle.
Don’t know what those acronyms mean? Don’t Repeat Yourself, and Once And Only Once principle. Not repeating the same code in different places is the single most important thing you can do to make your project easy to maintain and to modify in the future. There are no exceptions to this rule. If you have repeated code in different places, it is a matter of time when you will see the project disintegrate. Do yourself a favor: don’t copy and paste. Modify the method, break it up into two. But don’t make it wet.
I broke this rule numerous times. And numerous times I was sorry that I did. I did it, and I got burned. It’s tempting to do so: easy and fast. But always consider the consequences.
I like my code to be clean: I like “girly” code. Duplication makes it dirty.
I can say with certainty: If your project has any duplication of logic, it is not a quality project. And after the first copy and paste, you take an express ride to a restaurant for a pasta meal. I mean “spaghetti.” I mean spagheti code. Do you want that?
I understand that you cannot always avoid duplication. For instance, if I have to modify an existing project, I might have to work with a lot of duplication (I hate it when I do), but for any new code that I write I have the following principle:
DUPLICATION PRINCIPLEDuplication is my enemy. I want no enemies; therefore, I will not create any duplication and I will try to kill it whenever I see it.
ReferencesThe Pragmatic Programmers: The DRY PrincipleCode like a girl, Creating Passionate Users blogOnce And Only Once, WikiWiki