Get Rid of Source Code Templates

Have you ever seen a project where all files begin with something like this?

/* * * some-file.cxx __ _ _ * ___ ___ _ __ ___ ___ / _(_) | ___ _____ ____ __ * / __|/ _ \| '_ ` _ \ / _ \_____| |_| | |/ _ \ / __\ \/ /\ \/ / * \__ \ (_) | | | | | | __/_____| _| | | __/| (__ > < > < * |___/\___/|_| |_| |_|\___| |_| |_|_|\___(_)___/_/\_\/_/\_\ * * Version: 234 * * Authors: Jack McRabbit <jack at example.com> * Mr. Coder <mr at example.com> * Joe Trainee <joe at example.com> * Ifixed Atypo <typo at example.com> * ********************* * * Copyright (c) 2000,2001,2002,2006-2008,2009 ZingFindle Corporation * All Rights Reserved. * ********************* * * IN NO EVENT SHALL ZINGFINDLE CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT * CONSEQUENTIAL, BLAH FLURB LEGALESE HERE, ARE YOU ACTUALLY READING THIS; * EVEN WHEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, BOB'S YOUR UNCLE. * * This is not a life-saving device and must not be used to build one, * or a medical device, oh, and also, this is not something you'd want * to put in a nuclear power plant, or anything else for that matter. * In fact, you'd be wise to print a copy, destroy all other copies, * including electronic copies, burn the printout, dissolve the ashes * in acid, and bury the waste into a hole in the desert. * * The above copyright notice and this permission notice must be included * in all copies of this file. * ********************* * ChangeLog: * * ifixed@rev 234: Updated copyright headers * ifixed@rev 233: Fixed typos in changelog * joe@rev 232: Added flooEnum. * <231 more lines of this...> * ********** * * TODO: ?? * ********** * * Description: write me * **** * */

I bet you have. Most projects have some kind of standard source code template which has the copyright and license text and placeholders for things like a description. All I have to say is: You don’t need a template. Stop using it.

Actually, that’s not all I have to say. Sorry. If you believe me already, you can stop reading now and go do something useful with your life. If you don’t quite believe me yet, please read on.



Why you don’t need to assert copyright

The most common objection to getting rid of these templates goes something like this:

“Hold on. We must keep at least the copyright notice in place, surely? We don’t want this to end up in the public domain or anything. A template is the best way to make sure everyone always puts a copyright in.”

No, and no. You don’t need a copyright notice in every file. Even if you did, a template is not a good mechanism to do it.

You don’t need to assert copyright because of the Berne Convention for the Protection of Literary and Artistic Works. It’s an international agreement which governs copyright. Almost all of the world has signed the convention by now:

The convention lays down the basics of what copyright is and what it means, and then says that “the enjoyment and the exercise of these rights shall not be subject to any formality”. This means that you don’t need to do anything to have copyright over your works. You don’t need to include a “Copyright ©” text. You don’t need to update copyright years, or figure out when to update them. I mean, should it be updated every time the file is edited? Or automatically at the turn of the year? Should each year be separately listed, or can I just give the first and last year?

You can include a copyright text, but the Berne Convention says it has no legal meaning. I say it’s useless baggage, especially the copyright years, so don’t put them in there at all.

Another common objection to leaving the copyright notice out goes like this:

“Everyone always puts a copyright notice in their files. There must be something to it, otherwise they wouldn’t do it.”

At this point, I would like to remind you of the story of the five monkeys.

Start with a cage containing five monkeys. Inside the cage, hang a banana on a string and place a set of stairs under it. Before long, a monkey will go to the stairs and start to climb towards the banana. As soon as he touches the stairs, spray all of the other monkeys with very cold, high-pressure water. After a while, another monkey makes an attempt with the same result — all the other monkeys are sprayed with cold water. Pretty soon, when another monkey tries to climb the stairs, the other monkeys will try to prevent it. Now, put away the cold water. Remove one monkey from the cage and replace it with a new one. The new monkey sees the banana and wants to climb the stairs. To his surprise and horror, all of the other monkeys attack him. After another attempt and attack, he knows that if he tries to climb the stairs, he will be assaulted. Next, remove another of the original five monkeys and replace it with a new one. The newcomer goes to the stairs and is attacked. The previous newcomer takes part in the punishment with enthusiasm! Likewise, replace a third original monkey with a new one, then a fourth, then the fifth. Every time the newest monkey takes to the stairs, he is attacked. None of the monkeys that are beating him have any idea why they were not permitted to climb the stairs or why they are participating in the beating of the newest monkey. After replacing all the original monkeys, none of the remaining monkeys have ever been sprayed with cold water. Nevertheless, no monkey ever again approaches the stairs to try for the banana. Why not? Because as far as they know that’s the way it’s always been done around here. And that, my friends, is how company policy begins.

Before the United States had signed the Berne Agreement in 1989, a copyright assertion was actually required if you wanted to enforce your copyright in the US. Everybody is still doing it, even though nobody needs to.

Why you don’t need the rest of it, either

Often, source code files repeat the file name in the file itself. I’ve never seen the point in that. It’s just one extra thing you need to remember to update if you rename the file. A big ASCII banner with the file name is positively crazy, but some people do that, too.

A list of authors is quite useless, as are version numbers and change logs. Any version control system will give you much better and much more accurate information for these automatically.

I also object to putting in a big fat license text to the beginning of each and every source code file, as is suggested in the GPL. If you want to later change the license to something else, you have a lot of work ahead of you. I’m not sure, but that may actually be why the GPL advocates putting in all that legal verbiage in every file. In my opinion, a concise reference to a separate license file should be enough.

A TODO list and a description are actually good to have. Sadly, these are the parts which most often are not filled in.

What you should do

For source code that you never plan to release to outsiders, you don’t need any standard header, template, license, or copyright. None. All you need to do is put the code in version control, so you can use the logs to prove that you wrote the code, and when you wrote it.

If you really feel you must at least refer to a license in open source code, you should be fine with just one line in each file.

If you do this, I don’t much care what you then put in the “LICENSE” file. You can put in all the copyright assertions and years for all I care. Just stop being a monkey; don’t borify the source code with attention stealing enterprisey legalese and copyrights.

/* See the file "LICENSE" for the full license governing this code. */

Oh, almost forgot. I am not a lawyer. This is not legal advice. Having to say that is stupid.

Related posts:

If you liked this, click here to receive new posts in a reader.

You should also follow me on Twitter here.