Thoughts on ActionScript

September 15th, 2011

Declaring variables "var i:int" instead of "int i" is a nice experiment, but I don't think it works. When I need to turn an assignment into a declaration or vice-versa, I now need to do it in two places (before and after the variable name) instead of just one.

That this gives an error about redeclaring i is just plain dumb:

  for (var i:int = 0; i < 10; ++i) { foo(i); }
  for (var i:int = 0; i < 10; ++i) { bar(i); }

It means I have to declare all my variables at the top, old-fashioned-C-style, or spend ages fixing up the declarations whenever I move code around.

I hate it when compilers enforce a "one class per file, with the same name" rule. I'd rather have my source files organized for the convenience of humans, not for the convenience of machines, thank you very much - if I have a bunch of small related classes, it's much better to have them in the same file.

No stack objects means that if you want to want to write a function that returns multiple values (e.g. a function that multiplies a matrix by a vector and returns a vector) you have to allocate an object to put the vector components in, which is very slow. For reproject I ended up just doing everything with plain values in a small number of functions - in C++ the code could be much more well-layered.

More riffing on software licenses

September 14th, 2011

Suppose you've written some software from scratch on your own time, using no resources from your employer. Suppose also that, having written it, you're proud of it and want to show it off to other people, perhaps get them to use it and give you feedback on it.

When doing this, the question invariably comes up of which software license you should publish it under, especially if other people would also like to contribute to it. If your aim is to eventually publish it as proprietary software you might choose a restrictive license like the Microsoft Reference Source License (Ms-RSL) which allows people to look at the source code but not to redistribute it. If your aim is to further the cause of eliminating all proprietary software you might choose a copyleft license like the GNU General Public License (GPL) which forbids use of the code in proprietary software. If your aim is to allow the software to end up running in as many places as possible, you might choose a permissive license like BSD.

Generally one will have multiple goals. For example:

  1. I want the software to be as useful as possible to its users.
  2. I want the software to do the greatest good for the greatest number of people. Note that this isn't the same as (1), since software can be useful to those running it without doing good to society as a whole - consider the case of the software controlling the machines at the cigarette factory.
  3. I want the software to be as widespread as possible to maximize my reputation.
  4. I want to make as much money as possible from the software, one way or another.

I think it's pretty difficult to predict at the start of a program's lifecycle which license is going to have which effect on which goals. Therefore the choice tends to be made on philosophical principles rather than sound science, such as "I believe the greatest good is done by making life as difficult as possible for developers of proprietary software" or "I believe that putting as few restrictions as possible on developers will make the software as useful as possible" or "I can maximize my chances of making money with this software by forbidding its distribution".

The philosophical principle which currently seems to make most sense to me is that goals 1, 3 and 4 are the important ones: the best way in the long term to make lots of money out of my personal programming projects is to make a good reputation for myself, which means getting my software running in as many places as possible, which means making it as useful as possible. Goal 2 would be nice but it's impossible to predict the long-term social good of any given action. The money spent on Microsoft software has done an enormous amount of good, for example, but that doesn't necessarily mean that all Free Software authors should drop what they are doing and contribute to proprietary software instead.

Suppose I write some piece of software X, and software developer Y takes this work and incorporates it into product Z, adding proprietary feature W and releasing the result as proprietary software. I haven't really lost anything in this situation - I (and the other users of X) can still do all the same things we could do before Y got involved (we can just pretend that product Z doesn't exist if we prefer to). Users who buy Z benefit because feature W is worth more to them than the cost they paid (both in money and reduced freedom) - they have one option that they didn't have before Y got involved. I (and the other users of X) benefit from publicity that Y creates around Z (especially if they don't try to hide the fact that Z is based on X) since that may itself draw more users to X (users who would not have otherwise heard about X and for whom W is not worth the cost).

As I see it there are a few disadvantages for copyleft licenses. One is that they are incompatible with existing non-copyleft software licenses (for example, one cannot take GNU code and use it in software that has an incompatible but still copyleft license). Another is that many companies have an aversion to copyleft licenses, eschewing such software entirely for the (not unfounded) fear that an accidental inclusion of copyleft software into their proprietary products will cause said products to become copyleft. In such cases the advantages for X above would never have happened.

Compatibility with other licenses is a big advantage for a permissive license - the BSD license is compatible with the GPL, for example (meaning you can take BSD code and release it under the GPL - the reverse is forbidden). Can we do better than the BSD license for compatibility? I think we can - even the BSD license includes some restrictions, such as the one that the warranty disclaimer must remain in place. I don't really see the advantage of warranty disclaimers - they seem like a CYA piece of legalese which doesn't actually do anything except take up space in licenses. I'm not a lawyer, but has anybody ever been sued because free software they wrote misbehaved and didn't have a warranty disclaimer? I doubt it - it seems like we can't even prosecute malware authors, who not only don't disclaim warranty but write software that's actively harmful.

My preferred software license would therefore be the most permissive one possible - essentially equivalent to not being copyrighted at all (same as "public domain" in many places). This state of affairs is compatible with any license that a third party chooses to use when redistributing the software. Maximum compatibility means greatest usefulness. Now, not all contributors to my software necessarily feel the same way, and that's okay - if Richard Stallman wants to contribute to my software but only on condition that his changes are GPL, that's okay - he can just make a GPL fork of my software and contribute to it. Others might contribute to my fork (if they share my views) or to the GPL fork (if they share Stallman's). One could even have a change-tracking system which would keep track of the license associated with each change, and therefore be able to tell you which license you can distribute the software under, if you include changes A, B and C. Forks could then compete on the merits of the resulting software - i.e. if one license tends to get more and better patches than another, its quality will rise and it will tend to be the one that gets used, so further patches will build on it and use the same license. If one particular license causes the software to be less useful, that license should die out. It would be an interesting ecosystem experiment to do. My suspicion is that the root "public domain"-like license would tend to be win more often than not because I would expect that most programmers would think the same way I do, preferring to get their patch into all license forks rather than just one. Also, restrictions can always be added in the future but removing them is much more difficult.

Downsides of copyleft

September 13th, 2011

As well as being not invulnerable and somewhat unnecessary, copyleft licenses may also be at least a little bit harmful to the software they are protected by, at least compared to permissive licenses.

The trouble with Free Software licenses (especially restrictive ones) is that they have a tendency to be incompatible with other licenses (even other Free Software licenses). Consider the sad case of the GCC manuals which underwent discussion on the GCC developers mailing list a while back. GCC is licensed under the GPLv3, whilst the documentation is licensed under the GFDL. Both of these are Free Software licenses, but because they contain slightly different restrictions, they are mutually incompatible - you can't take GCC source code and copy it into the GCC manual, nor can you take parts of the GCC manual and copy them into the source code. This means that the technique of literate programming is impossible - documentation can't be automatically generated from the code.

This could be solved if there was one single copyleft license that was used for everything, but I can't see that happening if the GNU project can't even standardize on a single license for its own projects.

It's important to note that these problems are caused by the restrictions imposed by the license, not the freedoms it guarantees - the same problems would occur with proprietary software, if the corresponding situation ever occurred.

Benefits of copyleft without copyleft

September 12th, 2011

Yesterday I showed that copyleft is not invulnerable. Today I will show that it is also (at least somewhat) unnecessary.

Let's again suppose that Microsoft wants to make a proprietary MS-GCC. They make version 1 (based on GCC 4.6.1, say) and it all works out great. But then GCC 4.6.2 becomes available and the proprietary patches don't work with the latest version any more. Microsoft wants to take advantages of the changes in 4.6.2 (otherwise MS-GCC will look bad compared to the latest FSF-GCC). So they re-do their patches. Each time a new GCC becomes available, Microsoft has some work to do to keep up.

It costs Microsoft money to keep doing this, so they look for an alternative. One such alternative is to assign copyright of these patches to the Free Software Foundation and contribute them to FSF-GCC. This might be a bit more work than just updating the patches, but it only needs to be done once. Then, further versions of GCC will include the Microsoft patches without any additional work on Microsoft's part.

This does, of course, mean that those proprietary changes become Free Software. That might not be such a big deal - chances are that if MS-GCC was really that much more useful than GCC, the equivalent functionality would be duplicated by GCC developers anyway (especially now that they know it's possible and useful).

So the "carrot" part exists independently of the "stick" part (the GPL) - even without any threat of a copyright violation lawsuit, there are still reasons to contribute your changes.

Copyleft loophole

September 11th, 2011

A while back I showed that it is possible to work around the anti-Tivoization provision of GPLv3. I've since realized that the GPL itself has a similar loophole.

The entire thing is predicated on the idea that if you change a program, you've created a "derived work" which therefore falls under the same copyright protection as the original. But is a change necessarily a derived work? If it doesn't include any of the original program, I don't think it necessarily would be if the change was distributed as a delta from the original. Normally a diff file says things like "in file x, look for the line that contains y and change it to z". Because this file will contain the line "y" (and even the filename "x", if it could be considered a creative work) it is a derived work of the original program. But one were to use a diff format that says "in the third file, change line 327 to z" that would contain no copyrighted information from the original, and could be distributed without restriction. There really isn't any difference between a code change and "mere aggregation".

What does this mean? Suppose you're Microsoft and you want to include GCC in Windows, modified with some proprietary algorithms and you don't want to release the source code. It turns out that this can be done. All Microsoft would have to do is include in the installer some code that will download the source (or binary) from a known location (perhaps from GNU servers, or a trusted third party's servers) patch it and (if necessary) compile it. Hey presto, there's the MS-GCC binary. The patch could be in the form of obfuscated code, object files or even (with some difficulty) binary deltas as long as care was taken to ensure none of the GNU-copyrighted works ended up in the Microsoft-distributed patch. Microsoft would not be committing copyright violation since none of the things they actually distributed contained any GNU-copyrighted code. The end-user would not be committing copyright violation either since they aren't distributing the software.

Essentially, with this hack, we've shown that the GPL is essentially equivalent to a BSD license. This isn't something that can be fixed by changing the license - it's a fundamental fact of copyright law.

The reason people don't do this is because it's more convenient to just release changes under GPL (so that a compiled binary of the aggregate can be released) than go through this hacky patching process. So it doesn't mean that copyleft isn't worth doing - in fact, I have heard it said that there are important parts of gcc which would never have been contributed if their authors' hands were not forced by the GPL.

Rewinding DVDs

September 10th, 2011

Some DVD players now remember where you stopped playing a DVD, even if the disk is removed. When you put the disk back in, it reads the disk identifier, looks in its memory to see if it has a previous position for that disk, and (if it does) starts playing from that point.

This is all very well, except for the situation where you have a rental house containing such a DVD player and a selection of DVDs to watch - at the end of the rental period, the remembered positions of the DVDs might not all be at the start, leading to somebody putting on a movie and it unexpectedly starting half way through.

What is needed to solve this problem is some kind of mechanism... for rewinding DVDs!

(Perhaps just a button on the front that says "rewind all" which causes all the remembered positions to be forgotten. Or what our DVD player does when it starts somewhere other than the beginning - putting a "press such-and-such button to start from the beginning".)

Fortunately the problem is rather less severe than the problem of rewinding VHS tapes, so we won't have to remember to rewind rental DVDs.

What to do about software patents

September 9th, 2011

Patents are an enormous problem for the software industry. Software development organizations can never be sure that the software they develop doesn't infringe on somebody else's patent, so the only defence against being sued for patent infringement is to build up an arsenal of your own patents on methods as trivial as you can get away with in the hope that if someone sues you can counter-sue them for infringing on your patents and end up cross licensing. This doesn't protect against patent trolls, though (who produce no products and therefore don't need to worry about infringing someone else's patents). Also, it favours large software development organizations over smaller ones - patents are very expensive to obtain.

The usual answer to this is that we should get rid of software patents altogether. Perhaps this will happen, if enough powerful companies are burnt by patent trolls. On the other hand, perhaps some software patents are actually useful for progress - perhaps there are areas of software development where patents make much more sense than copyright - where simply examining the end product would allow somebody to (without infringing copyright) copy the part that took hard work to discover (i.e. an idea rather than the implementation). Perhaps there are ideas could not have been had without the investment that a promise of patentability would bring. Perhaps the additional secrecy that would have to be put in place without patents would cripple the industry.

Here's a proposal for a different sort of patent reform, which aims to solve these problems:

First, get rid of all the patent examiners. They're doing a lousy job anyway, granting all sorts of patents on things which have been done before and which are perfectly obvious to a person skilled in the art. Many of these patents don't stand up in court, but it's still expensive to defend against attacks from bogus patents. Instead, the patenting process should be a simple rubber stamp - anyone can send in a description of their idea (preferably not written in patent-ese), have it published on the USPTO (or equivalent) website and hey presto, that concept is now patented.

Of course, that doesn't get rid of the problem of bogus patents - it just moves the workload from the patent office to the court, which seems like it would make things worse. So the next stage is to set up a special patent court. If A wants to sue B for infringing on A's patent, it all gets sorted out in this court. The court needs to find a person skilled in the art (PSITA) who is not affiliated with A or B, and also to determine if B referred to A's product or patent. If the patent is bogus, or if B is determined to have invented the same thing independently, then the patent is thrown out and A has to pay the costs of the entire proceeding. If the patent stands up and B is found to have based their product on A's product or patent, then B must suffer the usual consequences, including having to pay for the proceedings. So (assuming the system works justly) all B needs to do to say safe is not to read unexpired patents and not to refer to competitors products - there should be no cost to them for accidental infringement or bogus patents (which really amount to the same thing - if it's possible to accidentally infringe on a patent it's a bogus patent by definition).

The third element we need is a way for a B to be sure that the product they want to release doesn't infringe on any patents (or to find out which patents it does infringe on). In practice it isn't possible to avoid seeing all competing products, so this step is necessary. The costs of this step must be borne by B, since otherwise B could cost A a lot of money by frivolously requesting repeated patent checks. The benefit is that (assuming the report comes back clean) there is then no risk of B losing a patent court battle. This sounds like it would be a very expensive exercise since it's essentially the cost of a patent trial multiplied by the number of active patents - however, a properly indexed patent database should make it reasonable.

One other element I'd like to see is a "use or it lose it" rule for patents, like those for trademark infringement. If you hold a patent, become aware of someone infringing that patent, and not choose to sue them immediately, you lose that patent altogether. This avoids problems with "submarine" patents.

Energy saving idea

September 8th, 2011

One of the most inefficient things we do with energy is heat up water with it only to let most of that water (and most of the energy) go right down the drain when we take showers (baths are a little better because more of the energy goes into heating the house in the winter, but they do use more water).

So I think that if we were serious about wanting to save energy one thing we could do is try to encourage shorter showers by making people aware of how much energy they use. What I imagine is a little display that shows you how much energy you've used since the start of your shower (if you like you could factor in the cost of the water and sewage as well as the energy used to heat the water). For maximum effectiveness, I think the value displayed by the meter should be in units of local currency, and correspond to the amount you'd spend taking a shower of that length every day for a year - that way it feels like you're spending money really fast (of course, you'd really only be spending it at 1/365th of that rate so it's a bit of a psychological hack/cheat).

I think many people would appreciate such a device for the money it would save them, though I suppose some people might believe that long, guilt-free showers are worth that extra money.

The mathematical universe

September 7th, 2011

Max Tegmark's Mathematical Universe Hypothesis is extremely compelling - it's the only idea I've ever seen that comes close to the holy grail of theories of everything "Of course! How could it possibly be any other way!". And yet it seems unsatisfying in a way, perhaps because it's conclusion is (when you think about it for a bit) completely obvious. Of course the universe is a mathematical structure containing self-aware substructures - what else could it be?

Also, if it is true then it leaves a lot of questions unanswered:

  • What is the mathematical structure that describes our universe?
  • What is the mathematical definition of a self-aware substructure (SAS)?
  • If any mathematical (or even computable, or finite) structure that contains SASs exists in the same way for those SASs that our universe exists for us, why is our universe as simple and explicable as it is (Tegmark calls this the "measure problem").

My feeling is (as I've said on this blog before) that it's extremely likely that our universe is in some sense the simplest possible universe that supports SASs (i.e. the "measure" punishes complexity to the maximum possible extent). I have no a priori justification for this, though - it just seems to me to be the most likely explanation for the third point above. While it may seem unnecessary to have three generations of leptons and quarks, I strongly believe that when we have a more complete theory of physics we'll discover that they are completely indispensible - a universe like ours but with only a single generation of these particles would either be more complex (mathematically speaking) or make it impossible for SASs to exist. I suppose it is possible however, that when we do find the theory of everything (and/or a theory of SASs) we'll be able to think of a simpler structure in which SASs are possible.

The other thing about MUH is that I'm not convinced that it really does make any predictions at all, because it seems like whatever we discover about our universe with respect to the other possible universes in the Level IV multiverse can be made consistent with MUH by an appropriate choice of measure.

Issues as political proxies

September 6th, 2011

Suppose you own a large successful business which makes money by telling customers things they want to hear - reassuring stories, comforting platitudes and advice and guidance about how to live their lives. Suppose also that, for tax reasons, you are not allowed to use your influence over your customers to push them towards voting for one particular candidate over another, and you're also not allowed to donate any of the company's profits to political parties or candidates.

However, you'd still prefer to have one candidate elected over another because your preferred candidate might lower your taxes or give you more freedom to run your business the way you want to run it, or maybe just because he's a good customer. How could you covertly support that candidate?

One thing you could do is a pick a couple of social issues which aren't fundamentally a big deal to you one way or another but which differentiate your preferred candidate from their opposition and which the opposition is unlikely to change their minds on (perhaps because they are objectively correct in their position). Then you can use your platform to tell your audience that your preferred position on said social issues is vitally important, and deciding the wrong way on them will lead the country to ruin. You don't even need to mention the names of the political candidates or the upcoming election to your audience at all - they can figure out themselves what they need to do.

For this reason I think we need to avoid making "tax deductions for political neutrality" deals - it's too easy for the organizations in question to be covertly politically non-neutral and the tricks they use cause pressure to move candidates away from objectively correct positions in this kind of issue.