Improve Code Quality by Disabling Copy and Paste

Integrated Development Environments (IDEs) should ship with Copy and Paste disabled by default in an effort to improve code quality. I acknowledge this is an extreme position that will not be popular by the majority of those who happen to read it.

Reasons why Copy and Paste should be disabled by default.

  1. It promotes what I have to believe is the most frequent code smell; duplicated code.

    Recently I was upgrading some commercial libraries and it was found to cause problems in numerous areas of the application. This is par for the course whenever you wait two years to upgrade libraries. I was appalled to learn that nearly character for character code had been repeated no less than 5 times within a single file. To better put this into perspective, the source file was 1800 physical lines when I checked it out and 1100 lines when I checked it back in; nearly a 40% reduction.

    I imagine the development went something like this. The programmer started by making the initial segment of code and got that working to their satisfaction. Once it was finished they went down to the next set of requirements and found that it was nearly identical, but with a few variations to the code they had just written. They took the code from before, duplicated it, and then modified it slightly to fulfill the second requirement. This repeated 5 or more times and allowed the author to finish their code quickly, which naturally makes most programmer’s bosses happy.

    I believe it’s natural for all people to want to do the least amount of work possible to accomplish a given goal. I jokingly call this being lazy and genuinely believe it’s a positive thing for a wide variety of careers; software developers included.

    The problem here is that it is easier to copy, paste, and then alter the already working code than it is to break it out into reusable functions, classes or extension methods. Imagine for a second that Copy has been disabled.

    It’s clear the author already recognized that the problems were similar enough to use the previous code as a starting point. Since they would be unable to duplicate the code via copy and paste it would be advantageous to them, at that very moment, to move that code into a common area.

    This is the main reason why disabling copy and paste in IDEs would encourage better quality code. It eliminates the requirement to have foresight to the future maintainability of the code or a desire to produce high quality code and transitions it to being the easiest way to do it right now.

  2. It would promote writing reusable code from the very first time you start to program.

    I think anyone who has been programming for any length of time can remember a time where design decisions they made have come back to bite them hard. This is frequently how I learn new programming techniques. I run into a problem that’s going to be difficult to fix due to poor design and I find a new technique that makes it easier. Mistakes are essential to learning.

    With that in mind it may seem contradictory that I want to discourage beginners from making this very common mistake. The thing with code smells, in particular duplicated code, is that the code will work perfectly fine and it is only when it is revisited that the problem becomes apparent. For beginning developers this may never happen until long after the bad habit has been learned.

I’m not suggesting that all ability of pasting code should be removed, just the repeated pasting of code. Cut and paste should remain as it’s a convenient way to move code around. I would just like to see the paste buffer cleared after code is successfully inserted.

I realize that even with the measure described here it’s still going to be possible to duplicate code via a plain jane text editor that you use as a scratch pad or simply by typing the same thing over and over again. My suggestion is that by making it inconvenient it would encourage the better practice and improve code quality.

Highway of Life

Borrowing an idea from a popular song and gathering my thoughts of what I have always considered fate to be I’ve formulated the following:

Life is an intricate series of highways small curvy ones provide surprises & adventure at every turn, larger straight roads are reliable and allow you to travel great distances quickly. Your life is a constant journey, where you stop only to sleep.

Potential decisions are represented by intersections and on-ramps. Your choices reflected by turns, none are final, some merely more difficult to change than others.

Happiness is found by taking the correct combination of small roads to keep life interesting and large roads to accomplish your goals and live your dreams.

Both types allow for hiccups along the way. Flat tires, bent rims, lost keys, and other malfunctions may occur at anytime to slow you down or shift your path.

Relationships in life occur when people meet and choose to travel down the same path, or at least agree to cross paths regularly. Sadly (or happily) peoples’ paths sometimes separate. Fortunately travelers find that many roads cross more than once, and may find themselves in a renewed relationship once again. Alternatively sometimes peoples’ paths can cross that should not and result in a crash.

Family and friends can serve as guides through the confusing highways of life. Urging you to stay on certain roads and helping to navigate you back to roads you have unintentionally lost. Ultimately the route you take is up to you and you alone.