Minification vs the GPL

A not-entirely-theoretical question about open source software licensing came up at work the other day. I thought it was interesting enough to warrant a quick dive into the philosophy of minification, and how it relates to copyleft open source licenses. Specifically: does distributing (only) minified source code violate the GPL?

If you’ve come here looking for a legally-justifiable answer to that question, you’re out of luck. But what I can give you is a (fictional) story:

TheseusJS is slow

TheseusJS is a (fictional) Javascript library designed to be run in a browser. It’s released under the GPLv3 license. This license allows you to download and use TheseusJS for any purpose you like, including making money off it, modifying it, or redistributing it to others… but it requires that if you redistribute it you have to do so under the same license and include the source code. As such, it forces you to share with others the same freedoms you enjoy for yourself, which is highly representative of some schools of open-source thinking.

Screenshot showing TheseusJS's GitHub page. The project hasn't been updated in a year, and that was just to add a license: no code has been changed in 12 years.
It’s a cool project, but it really needs some maintenance this side of 2010.

It’s a great library and it’s used on many websites, but its performance isn’t great. It’s become infamous for the impact it has on the speed of the websites it’s used on, and it’s often the butt of jokes by developers: “Man, this website’s slow. Must be running Theseus!”

The original developer has moved onto his new project, Moralia, and seems uninterested in handling the growing number of requests for improvements. So I’ve decided to fork it and make my own version, FastTheseusJS and work on improving its speed.

FastTheseusJS is fast

I do some analysis and discover the single biggest problem with TheseusJS is that the Javascript file itself is enormous. The original developer kept all of the copious documentation in comments in the file itself, and for some reason it doesn’t even compress well. When you use TheseusJS on a website it takes a painfully long time for a browser to download it, if it’s not precached.

Screenshot showing a website for the TheseusJS API. It's pretty labyrinthine (groan).
Nobody even uses the documentation in the comments: there’s a website with a fully-documented API.

My first release of FastTheseusJS, then, removes virtually of the comments, replacing them with a single comment at the top pointing developers to a website where the API is fully documented. While I’m in there anyway, I also fix a minor bug that’s been annoying me for a while.

v1.1.0 changes

  • Forked from TheseusJS v1.0.4
  • Fixed issue #1071 (running mazeSolver() without first connecting <String> component results in endless loop)
  • Removed all comments: improves performance considerably

I discover another interesting fact: the developer of TheseusJS used a really random mixture of tabs and spaces for indentation, sometimes in the same line! It looks… okay if you set your editor up just right, but it’s pretty hideous otherwise. That whitespace is unnecessary anyway: the codebase is sprawling but it seldom goes more than two levels deep, so indentation levels don’t add much readability. For my second release of FastTheseusJS, then, I remove this extraneous whitespace, as well as removing the in-line whitespace inside parameter lists and the components of for loops. Every little helps, right?

v1.1.1 changes

  • Standardised whitespace usage
  • Removed unnecessary whitespace

Some of the simpler functions now fit onto just a single line, and it doesn’t even inconvenience me to see them this way: I know the codebase well enough by now that it’s no disadvantage for me to edit it in this condensed format.

Screenshot of a block of Javascript code intended using semicolons rather than tabs or spaces.
Personally, I’ve given up on the tabs-vs-spaces debate and now I indent my code using semicolons. (That’s clearly a joke. Don’t flame me.)

In the next version, I shorten the names of variables and functions in the code.

For some reason, the original developer used epic rambling strings for function names, like the well-known function dedicateIslandTempleToTheImageOfAGodBeforeOrAfterMakingASacrificeWithOrWithoutDancing( boolBeforeMakingASacrifice, objectImageOfGodToDedicateIslandTempleTo, stringNmeOfPersonMakingDedication, stringOrNullNameOfLocalIslanderDancedWith). That one gets called all the time internally and isn’t exposed via the external API so it might as well be shortened to d=(i,j,k,l,m)=>. Now all the internal workings of the library are each represented with just one or two letters.

v1.1.2 changes

  • Shortened/standarised non-API variable and function names – improves performance

I’ve shaved several kilobytes off the monstrous size of TheseusJS and I’m very proud. The original developer says nice things about my fork on social media, resulting in a torrent of downloads and attention. Within a certain archipelago of developers, I’m slightly famous.

But did I violate the license?

But then a developer says to me: you’re violating the license of the original project because you’re not making the source code available!

A man in a suit sits outdoors with a laptop and a cup of coffee. He is angry and frustrated, and a bubble shows that he is thinking:"why can't people respect the fucking license?!"
This happens every day. Probably not to this same guy every time though, but you never know. Original photo by Andrea Piacquadio.

They claim that my bugfix in the first version of FastTheseusJS represents a material change to the software, and that the changes I’ve made since then are obfuscation: efforts short of binary compilation that aim to reduce the accessibility of the source code. This fails to meet the GPL‘s definition of source code as “the preferred form of the work for making modifications to it”. I counter that this condensed view of the source code is my “preferred” way of working with it, and moreover that my output is not the result of some build step that makes the code harder to read, the code is just hard to read as a result of the optimisations I’ve made. In ambiguous cases, whose “preference” wins?

Did I violate the license? My gut feeling is that no, all of my changes were within the spirit and the letter of the GPL (they’re a terrible way to write code, but that’s not what’s in question here). Because I manually condensed the code, did so with the intention that this condensing was a feature, and continue to work directly with the code after condensing it because I prefer it that way… that feels like it’s “okay”.

But if I’d just run the code through a minification tool, my opinion changes. Suppose I’d run minify --output fasttheseus.js theseus.js and then deleted my copy of theseus.js. Then, making changes to fasttheseus.js and redistributing it feels like a violation to me… even if the resulting code is the same as I’d have gotten via the “manual” method!

I don’t know the answer (IANAL), but I’ll tell you this: I feel hypocritical for saying one piece of code would not violate the license but another identical piece of code would, based only on the process the developer followed to produce it. If I replace one piece of code at a time with less-readable versions the license remains intact, but if I replace them all at once it doesn’t? That doesn’t feel concrete nor satisfying.

Screenshot showing highly-minified HTML code (for this page) which is still reasonably readable.
Sure, I can write a blog post in just one line of code. It’ll just be a really, really, really long line… (Still perfectly readable, though!)

This isn’t an entirely contrived example

This example might seem highly contrived, and that’s because it is. But the grey area between the extremes is where the real questions are. If you agree that redistribution of (only) minified source code violates the GPL, you’re left asking: at what point does the change occur? Code isn’t necessarily minified or not-minified: there are many intermediate steps.

If I use a correcting linter to standardise indentation and whitespace – switching multiple spaces for the appropriate number of tabs, removing excess line breaks etc. (or do the same tasks manually) I’m sure you’d agree that’s fine. If I have it replace whole-function if-blocks with hoisted return statements, that’s probably fine too. If I replace if blocks with ternery operators or remove or shorten comments… that might be fine, but probably depends upon context. At some point though, some way along the process, minification goes “too far” and feels like it’s no longer within the limitations of the license. And I can’t tell you where that point is!

This issue’s even more-complicated with some other licenses, e.g. the AGPL, which extends the requirement to share source code to hosted applications. Suppose I implement a web application that uses an AGPL-licensed library. The person who redistributed it to me only gave me the minified version, but they gave me a web address from which to acquire the full source code, so they’re in the clear. I need to make a small patch to the library to support my service, so I edit it right into the minified version I’ve already got. A user of my hosted application asks for a copy of the source code, so I provide it, including the edited minified library… am I violating the license for not providing the full, unminified version, even though I’ve never even seen it? It seems absurd to say that I would be, but it could still be argued to be the case.

Diagram showing how permissive software licenses are generally compatible for use in LGPL or MPL licensed software, which are then compatible for use (except MPL) in GPL licensed software, which are in turn compatible for use (except GPL 2) with AGPL licensed software.
I love diagrams like this, which show license compatibility of different open source licenses. Adapted from a diagram by Carlo Daffara, in turn adapted from a diagram by David E. Wheeler, used under a CC-BY-SA license.

99% of the time, though, the answer’s clear, and the ambiguities shown above shouldn’t stop anybody from choosing to open-source their work under GPL, AGPL (or any other open source license depending on their preference and their community). Perhaps the question of whether minification violates the letter of a copyleft license is one of those Potter Stewart “I know it when I see it” things. It certainly goes against the spirit of the thing to do so deliberately or unnecessarily, though, and perhaps it’s that softer, more-altruistic goal we should be aiming for.

× × × × × ×

Meat To Please You

There’s something that I just don’t understand about vegetarians. It’s something that I didn’t understand when I mercilessly teased them, and it’s something that I still don’t understand now that I am one:

What’s with the fake meat?

Quorn ‘Roast Chicken Style Slices’. No chickens were harmed in the making of this chicken.

You know the stuff I’m talking about: stuff made out of mycoprotein or TVP or soya that’s specifically designed to emulate real meat in flavour (sometimes effectively) and texture (rarely so). Browse the chilled and frozen aisles of your local supermarket for their “vegetarian” section and you’ll find meatfree (although rarely vegan) alternatives to chicken, turkey, beef and pork, presented here in descending order of how convincing they are as a substitute.

Tesco ‘vegetarian’ hot dogs. There’s actually a distinct possibility that these contain MORE meat than their non-vegetarian counterparts.

Let’s be clear here: it’s not that I don’t see the point in faux meat. It has a few clear benefits: for a start, it makes vegetarianism more-approachable to omnivores who are considering it for the first time. I’ve tried meat substitutes on a number of occasions over the last couple of decades, and they’ve really improved over that time: even a meat-lover like me can be (partially) placated by the selection of substitutes available.

Man, this photo of a BLT looks more delicious every time I use it on my blog. Why do I torture myself this way?

And while I slightly buy-in to the argument that the existence of these fake meats “glorifies” meat-eating, perhaps even to the extent as to under-sell vegetarianism as a poor substitute for the “real thing”, I don’t think that this is in itself the biggest problem with the fake meat industry. There’s a far bigger issue in question:

Why are we stopping here?

A dodo. Apparently it tasted somewhat like turkey, only tougher: there are dozens of accounts of its preparation and consumption.

If we’re really trying here to make “fake meats”, then why are we setting our targets in-line with the commonly-eaten “real meats”? Why stop at chicken and turkey when we might as well make dodo-flavoured nut roasts and Quorn slices? Sure, they’re extinct, so we’ll probably never have real dodo meat: but there’s no reason that the manufacturers of artificial meats can’t have a go. There are dozens of accounts of the preparation and consumption of dodos, so we’d surely be able to emulate their flavour at least as well as we do the meats that we already produce substitutes for.

A tin of unicorn meat: a good source of sparkles! Also cures poison, detects virgins, etc.

Why stop there? We might as well have tins of unicorn meat, too, a meal already familiar to those of us who’ve played more than our fair share of NetHack. How about dragons, or griffins, or the Vegetable Lamb of Tartary? If we’re going to make it up as we go along when we make artificial bacon, we might as well make it up as we go along when we make basilisk-burgers and salamander-sausages, too.

There’s a reason, of course, that we don’t see these more-imaginative meat substitutes. Many of the most loyal fake-meat customers are the kinds of people who don’t like to think about the connection between, for example, “chicken” (the foodstuff), and “chicken” (the clucking bird). To be fair, a lot of meat-eaters don’t like to think about this either, but I get the impression that it’s more-common among vegetarians.

But seriously, though: I think they’re missing a trick, here. Who wouldn’t love to eat artificial pegasus-pâté?

× × × × ×

Insanity Clause

This was one of my most-popular articles in 2009. If you enjoyed it, you might also enjoy:

I believe that it is ethically wrong to lie to children about the existence of Santa Claus. And, as it’s a topical time of year – and because I know that this view brings me into conflict with the views of many others (I’ve certainly had more than a couple of arguments about this before) – I thought that I’d explain my thinking.

"I'm not real, but don't tell anyone!"
"I'm not real... but don't tell anyone!"

Bias of background

I probably ought to come clean, first, about my own background. There’s a certain bias that people can have towards their own upbringing: the implicit assumption that the way one was brought up is somehow the best or the most-correct way. I’d like to think that I’m speaking from a position of rationality as well as morality, but I can’t deny that my judgment may be clouded by my own childhood.

I never believed that Santa was real, and was never encouraged to. My family played out a whole variety of modern, secular Christmas traditions, such as leaving out a mince pie for Santa, hanging stockings, and decorating a tree. But these were always understood to be what they actually were. There was never an illusion that the mince pie wasn’t being eaten by my dad just minutes after he’d checked that I’d finally managed to curb my excitement get to sleep (even without a belief in the patently mythological, Christmas can still be an exciting time for a child).

What’s the harm?

When I was growing up, I came into contact with many children for whom the Father Christmas myth was very real. I gather that they’re still remarkably common… and who can blame parents: perpetuating the Santa lie can provide a very easy and pervasive way to control the behaviour of their children!

For the vast majority of these children, the revelation of the lie was a harmless experience: over time, they developed doubts, from the childish (“We don’t have a chimney? How can Santa slide down radiators?”), to the logical (“Reindeer can’t fly! And how big is a sleigh that can carry presents for every good child on Earth?”), to the profound (“Why does Santa give the children of rich parents more expensive gifts than the children of poor parents?”). They’d hear stories from other children about the falsehood of the Christmas stories when they spoke to other children or, often, older siblings. Many would eventually challenge their parents on these lies, and most of these parents would then come clean, correctly judging that the lie had run it’s course. So what’s the harm?

There are some children who didn’t come off so well. I’ve seen children bullied at school and in social settings as a result of clinging to their belief in Santa. One kid I knew – bolstered by his mother’s ongoing lies (she would later claim that she thought he knew, but was just “playing along”) – genuinely believed in Santa until he was 14 years old, defying all argument to the contrary, and suffered so much that he ceased to gain any enjoyment at all from the festival for years to come.

I’ve spoken to parents who have attempted to justify their decision to lie to their children by dismissing it as only “a white lie”, something which does more good than harm, and I can see their argument. But for some children, as we’ve seen, this lie can spiral out of control, and even if this were to happen with only one in a thousand children, I wouldn’t personally want to take the risk that it was a child of mine.

One of Santa's biggest benefits is that he has a list of where all the naughty girls live.

That Magical Christmas Feeling™

A common response to my claim that lying to children about Santa is ethically wrong is that there is something particularly special (or “magical”, it is often said) about being able to believe in Santa. Those who make this claim invariably come from a background in which they were encouraged to believe in him, and they frequently talk of wanting their children to be able to have the same experience as them. (I would speculate that there’s a large crossover between this group of people and the group of people who would rather their children were brought up with their religious beliefs, or lack thereof, than be given the opportunity to make their own choices, too).

Having experienced life as an a-santaist, I can say that there never for a moment felt like there was something missing from my childhood Christmases. Children have a rich and beautiful imagination and a way of looking at the world which will find wonder and magic, if they want it, regardless of the untruths they’re told. Imposing false beliefs as truths on healthy young minds does not result in a net addition of “magic”. At best, all that is achieved is that the child fantasies about a specific lie, perhaps one that the child’s caregivers can relate to. We’ve discussed a couple of the worth cases already, and these aren’t isolated incidents.

Christmas can be a magical time anyway. There’s time away from school (for children of schoolgoing age), a chance to see distant relatives, the giving and receiving of presents (how can I have left this until third in the list!), following unusual and exciting traditions, eating special food, the potential for snow (at least in this hemisphere), and a time for telling special stories and singing special songs. Special events are magical, and that’s true whether or not you subscribe to any particular religious or secular holidays. For a child, birthdays are magical, bonfire night is magical (ooh! fireworks!), the summer solstice is magical: whatever you’ve got can be magical when you’ve got a child’s imagination.

Think back to whatever family traditions you had as a child, especially the ones you had to wait a whole year for. They’re all special, all by themselves. You can enjoy eating delicious chocolate eggs without believing in either a magical rabbit with a confusing reproductive system, the crucifixion of the embodiment of a deity, or spring coming forth thanks to the earned favour of the fertility gods. Sorry, what were you saying? I was still thinking about chocolate.

Santana - a full 100% more real, but only 95% less magical - than Santa

So, no Santa at all, then?

If you were paying attention, you’ll have seen that I said “telling special stories and singing special songs”. My childhood was a secular one, certainly, but that doesn’t mean that it wasn’t full of stories of a jolly red man, songs about cervines with nasal photoluminescence, and so on. I enjoyed stories about a gift-giving magical man, just like I enjoyed stories about anthropomorphic talking animals: and it’s okay to understand these things for just what they are: stories! There’s perhaps something a little special in stories about Father Christmas in that they’re told pretty-much exclusively at Christmas time (and, perhaps, a little much – how many Christmas-themed movies are scheduled for television broadcast this winter?), but we don’t have to treat them as if they’re real.

My rules are pretty simple. If you (a) know something to be false and (b) teach it to a child to be real with (c) the intent for them to believe it wholeheartedly and for an extended period of time, you’re abusing the position of trust in which that child has placed you. (a) provides an exception for religious upbringing, (b) provides an exception for relationships in which there is not a disparity of power, and (c) provides an exception for whatever so-called “white lies” you feel that you need: that’s a pretty hefty lump of exceptions, if you need them – but still people raise objections.

Here’s what Santa means to me. To me, “Santa” is, and has always been, the embodiment of anonymous gift-giving: the genuine “spirit of Christmas”, if you like. And given my way, that would be what I’d want to teach my children, too. I’m not for a moment denying anybody the magic of the season, I’m just saying that there’s a big difference between Santa as an abstract concept (like a storm “wanting” to break) and Santa as a real, albeit magical, being (like Poseidon sending the storm).

It’s a matter of trust

For me, this all comes down to trust. I don’t want to lie to my children. It’s not a difficult concept to understand: the only difference between me and a large number of other people is that they choose a different definition of “lie”. For the virtually all children who discover that they’ve been deceived about Santa, their trust in their parents remains fundamentally unharmed. For some, it’s dented for a short while but then comes back. But this still doesn’t make it right.

I want to be somebody who my children will always know that they can trust. I want them to know that I will not lie to them or deceive them. I want to be somebody who they can turn to for advice. I want to be somebody who they know will put them first, even in spite of tradition and convention.

That’s where I stand. Let’s here what you guys think.

Now this is the kind of Santa that I can get behind.

But first, there’s one more argument…

…that I’ve heard recently. I’ve heard it put that it’s beneficial to lie to children about Santa because it teaches them not to trust everything they hear, teaches them to be critical thinkers, etc.. That being taught a lie will toughen them against other lies that they will be given to them later in the big, wide, and cruel world.

This argument holds no weight with me. Do these same parents like to beat up their children “just a little” so that if they get into a fight at school, it won’t be so bad? Do they lock up and abuse their kids so that if they’re kidnapped and raped that it isn’t so hard on them?

In my mind, a lie that you keep up for years on end is no longer a harmless lie. When I want to teach my kids about deceit, I’ll perform magic tricks for them. The first time you perform a magic trick for a child, they genuinely believe it – how did he make that coin appear from behind my ear? Leave it for a minute or so (a minute can be an eternity when you’re a kid). Then I’ll show them how it’s done. I’ll teach them to do the trick themselves, and they’ll see for themselves that magic is an illusion. Plus, they’ll have learned a cool trick.

The world is full of many very clever illusions and tricks, and often you can’t see how they’re done, but that doesn’t mean that they’re magic. There’s no shame in not knowing all the answers, but looking for answers is a noble and beautiful thing. I want to foster in my children a natural suspicion of magic, so that they’re better-able to avoid being conned by those who would do them harm. And I can achieve this without lying to them for more than a few minutes at a time. Shove that in your stocking, Santa.

DISCLAIMER: THIS BLOG POST CONTAINS SPOILERS ABOUT THE NATURE OF SANTA CLAUS. IF YOU BELIEVE IN SANTA CLAUS, PERHAPS YOU SHOULDN’T HAVE READ IT.

No offence intended to those who genuinely believe that Poseidon is the master of storms, naturally.

×