Avoid the agony of copypasta.

Problems are replicated when code is copied.

Copying and pasting code is a rookie move. The temptation is great, as new developers search the web for solutions to their problems and end up copying some code they saw posted on StackOverflow. Or maybe they simply copy routines to various parts of the application as they need it.

Ultimately this can lead to performance and security problems. As the software gets improved and extended over time, not all copies are likely to be updated because the person making the changes may be unaware that a section of code has been copied multiple times. As a result, each different version of the code section will start to exhibit different behavior. This problem can hide some challenging bugs.

For these and other reasons, one should endeavor to reduce code duplication. Fortunately, there are tools to help identify duplicate code, and you should use them. Even better is to refactor the code and separate out concerns. As you move logic to appropriate helper and utility classes, it becomes more evident that a particular tool can be used in multiple parts of the code, replacing code copies with calls to a single implementation of the class.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: