Help keep your code sanity

Ever think to yourself “Oh I have this project to do and I’ll just cut and paste the code from there and tweak it?” And now you have two copies that are a lot alike but maybe not exactly the same.

And then you do this over & over and now you have many copies of that code?

How do you deal with issues when you find them ?

Which copy is the newest & the most correct ? And which one is the right good copy to use as the basis for yet another copy ?

I’ll admit that I will copy & paste code to examine it. Play with it to see how it breaks. And then I throw it away and fix the real single working copy that IS the master for all others.

And there are some neat tools for this like Snippets for BitBucket Server

Copy & paste coding is fast. Repetitive. And it has issues. Which is why copy-paste programming is used mostly as a negative comment on coding style.

And it can be dangerous

If you have the ability to avoid it by using submodules, includes, sub-projects in whatever version control system you’re using (you ARE using version control right?), or similar mechanisms I’d encourage you to do so.

It will help you avoid the proliferation of many different versions of the same code in all your projects.

And when you need to fix the code you can fix one copy and all your other projects can be updated with it.