The future of growth

Or, “among the many reasons I love Paul Krugman.”

Krugman reviews a Robert J Gordon book, “The rise and fall of American growth.”

I’ve just put this book on my library queue, so bear in mind I haven’t yet read it, but Krugman describes Gordon’s argument as essentially “recent-ish historical growth was due to the industrial revolution, we shouldn’t expect this to continue.”

Or in other words, if the grand narrative of human history is “hunting-gathering, 100,000 years of slow growth, agricultural revolution, 10,000 years of slow growth, industrial revolution” the next item up ought to be “slow growth.”

I’m deliberating phrasing things differently because in my view, this immediately raises the next question: “What’s the next revolution?” As near as I can tell not yet having read it, Gordon’s argument appears to be completely oblivious to the idea that there could be one coming.

Krugman doesn’t dwell on it much though:

Of course, Gordon could be wrong: Maybe we’re on the cusp of truly transformative change, say from artificial intelligence or radical progress in biology (which would bring their own risks).

But he still nails it. Modern futurists spend much blathering on AI, of course. But the real revolution is lurking the other suggestion.

If we look at what it takes to have a revolution up to the same standards as the industrial and agricultural revolutions, we have a pretty damn high bar to meet. You need to change pretty much everything about life. Where we live, what we do, where all the material things around us come from, how our society is organized.

Even fictional imagining of the future with AI (such as Iain M Banks, our lord and savior) still assumes a basically industrial society. To actually make it futuristic, you need to take absurd liberties with physics to imagine doing things differently than today. (Um, essentially free energy from nowhere. Also, FTL. Oh, magical remote manipulation, somehow!)

Synthetic biology could actually have that civilization-changing impact, someday, but futurists don’t seem to pay it enough attention. (Narrow applications to human genetic manipulation excepted, thanks to transhumanists.)

The future is living in a custom genetically engineered tree house where steakfruit grows in your pantry.

Posted in Futuring | Leave a comment

Wind powered cars

There’s a neat, long article over at Wait But Why that I found quite interesting. It purports to be about Elon Musk and Tesla (which might dissuade some readers) but it’s actually about climate change and electric cars.

I wanted to add something to it, but that means you should probably read that article first.

One of the first things everyone hears about when looking at renewable energy like wind and solar is variability. Everyone upon hearing that variability of wind is a problem thinks the same thing: gosh, the wind might not blow and there won’t be enough power!

This is wrong. The actual variability problem is the other way around: high winds create too much power. (Why aren’t low winds a problem? Well, it’s possible for them to be an issue, but low wind speed is actually pretty rare 100 meters up. The kinds of calm days we experience are actually hot-air bubbles close to the surface protecting us from the winds higher up.)

Wind becomes uneconomical if you can’t actually use the power you’re generating and it’s a waste. This is why people talk about “grid infrastructure upgrades” as something necessary to support wind power. Iowa’s got 30% of their power coming from wind, and so they want to build a connection to Chicago. To sell power, not buy it. Because excess is what we worry about.

Enter electric cars and the “smart grid.” How do you use up excess energy? Why not offer it up at a discount to anyone willing to defer drawing it until an excess is available? Your car might have a couple of slider settings that look like this:

Car charging diagramThe end result? A fleet of electric cars absorbs excess capacity when we need it to, and also reduces electrical demand when there isn’t excess capacity. Smoothing out demand to match supply.

This is one of the things I love about energy innovations: synergy. Electric cars and wind energy make each other better. There’s also a nice synergy between nuclear energy (as baseload) and grid storage… but perhaps another day.

Posted in Energy | Tagged , | Leave a comment

Algebraic data types: without them, we all suffer

Perhaps you’ve heard of “stringly typed” code. The use of strings instead of actual, you know, proper data structures, in places where it seems completely inappropriate.

Why do programmers write such things? I’m sure some of it is simple bad programming. But there are some legitimate advantages to stringly typed code, if you can manage to hold your nose long enough to give it a fair evaluation.

  • Strings behave like actual values. You can pass them around and copy them quite easily in pretty much all languages.
  • You don’t have to write any serialization/deserialization code. Woohoo!
  • Write-fast programming! Not having to design schemas and write data structures with all the associated “boilerplate” code is the same reason many give for using dynamic languages.

I can’t in good conscience write a list of advantages without also mentioning the disadvantages:

  • Difficult to use and understand. No clues given for what values should be passed in, or might be expected to come out. Documentation becomes harder and more important, and documentation is already rarely good enough.
  • Difficult to refactor. Since way too many things are strings, it’s very hard to find all the implications of a code change. Testing also becomes harder.
  • Biggest source of security vulnerabilities since buffer overflows. Not just SQL-injection, it’s very easy for validation code to disagree with all the possibilities for how the code consuming the string might behave. To see both of these sorts of bugs in action at the same time, consider how mysql_escape_string was buggy and mysql_real_escape_string became necessary.

Okay. So, the question is: can we get rid of these advantages? Well, let’s take one small step in the right direction to: JSONly typed code. It’s all the rage these days. You tend to see it less “in-the-small” compared to stringly typed, so you’re less likely to find simple functions expecting a JSON true/false object the way you can find methods expecting one of “true” or “false” as strings. But it shows up everywhere, regardless of appropriateness these days. Configuration files, same-machine IPC mechanisms, databases…

Let’s compare it to the advantages of stringly typed code:

  • Stringly typed values are already difficult to mutate, so we can get value-like semantics from JSON by simply treating it as immutable without any real loss.
  • Serialization/deserialization code is already written for us in a library. Score!
  • All the “boilerplate” data structure construction / visiting code: also in the library.
  • Still no schemas to think about writing, so code fast! Zoom zoom!

So, a slight cost in using a library, but with mostly the same advantages and with one extra really huge one:

We can actually represent tree-like data.

Think about your standard, popular, typed languages: C, C++, Java, C#. Actually representing tree-like data is a horrible mess of writing a ton of classes along with visitor interfaces and so on. It’s a pain.

Think about your standard, popular, relational databases: MySQL, Postgres, SQL Server. How do you represent tree-like data? I’m not even sure this admits a one-sentence description, so let’s go with: it’s a pain.

Dynamic languages (equivalently, NoSQL databases) manage a little better, simply because they don’t have to bother with writing down overly-verbose boiler-plate code. JSON as a datatype brings these advantages even to typed languages.

But it comes at the cost (of course) of actually having meaningful types. Consider still the same disadvantages listed for stringly typed code:

  • It’s still completely up to good documentation to know what to pass in, and what to expect out. I think every web developer has encountered an infuriating API that gives undocumented JSON error responses sometimes.
  • Refactoring is still a concern, but the use of JSON is more often at interface boundaries where API stability is expected. But this can still result in seemingly innocent changes causing problems with clients, simply because the interface is under-specified.
  • Security vulnerabilities are apparently massively reduced, but I suspect this is partly because this is an area where security researchers haven’t yet had a play day. JSON does seem to significantly reduce the possibility of radically reinterpreting the meaning of a value, but “validation vs interpretation” mismatches are still possible, and I’m sure they’re out there.

So, how do we completely fix all these disadvantages, while retaining all the advantages? Well, the answer is: algebraic data types.

JSON, after all, is just one simple algebraic datatype:

data JSONValue
 = JSONNull
 | JSONBool   Bool
 | JSONFloat  Double
 | JSONString String
 | JSONArray  [JSONValue]
 | JSONObject (Map String JSONValue)

That’s some simplified Haskell, but the important thing is: we’re almost done. All we need is some code to serialize/deserialize. We could even have Haskell make up its own code to do this for us, but it wouldn’t actually be the JSON syntax.

Compare that to the equivalent code we’d have to write in, say, Java. 7 short lines versus, what? A few hundred? And the code we write to consume/build these data structures is also going to be quite a bit simpler and shorter.

Let me pick another example. How about a (simplified) representation of C types?

data CType
 = CTypeBuiltin   [Qualifier] BuiltinCType
 | CTypePointer   [Qualifier] CType
 | CTypeTag       [Qualifier] CName
 | CTypeArray     CType (Maybe Int)
 | CTypeFunction  CType [CType]

Not too shabby for 6 lines. But consider what it would take to do this with classes.

Then consider what choice you’d make, if you wanted to store a table mapping names to types in SQLite.

As for the relative advantages and disadvantages:

  • We get values the same way JSON does: immutability.
  • We can automatically generate serialization/deserialization code, as long as the particulars of the syntax don’t matter too much.
  • We don’t need to write any boilerplate.
  • The code precisely documents the range of valid values.
  • The code is easily refactorable. I haven’t gone into pattern matching and exhaustiveness checking, but algebraic data types are an absolute dream for “change something, fix compiler errors, wow everything just works!”
  • The opportunities for validation errors are virtually eliminated. Our C types example requires only checking to make sure that a CName is actually a valid identifier (and thus not, say, a pile of arbitrary code). It’s possible to perfectly enforce this by making the constructor of a CName type always check this, and throw an exception otherwise. (Something that can’t be done for JSON.)

The lack of algebraic data types in modern languages and relational databases is, in my opinion, the biggest cause of frustration, error and bad code since the lack of generics. I hope one day even conservative languages (like C and Java) will incorporate them.

Posted in Programming | Tagged , , | Leave a comment

Human-computer interaction and programming

The other week, I was dismissive of an attempt at creating a “non-programming” sort of programming. I’d like to explain myself a bit more.

The trouble, I think, is that many people confuse the problem. Programming is pretty terrible, but I don’t think that’s because we write programs in a programming language. I think it’s because we write poor programs in poor languages, with poor tools, using poor libraries, that are all poor mostly because we’ve built everything on shaky foundations we can’t fix and basically because we still don’t know what we’re doing as an industry. So we’re quite fond of metaphors like “it’s held together with duct tape and bailing wire.”

When people try to create “non-programming” sorts of programming, they generally fix none of those issues. And they remove the successes we do have with languages. And they mistakenly believe that “ordinary” people are incapable of programming. And then they make a truly, horribly fundamental mistake: they try to make things graphical and clicky.

You see, I think there’s three basic levels of communication from humans to computers. There’s the “point and click” level, the expert “real-time” level, and then there’s the language level.

You’re probably familiar with all of these, but let me make sure I’m clear. We browse the web almost entirely at the “point and click” level. It’s essentially how we interact with tablets and smart phones.

For the expert “real-time” (for lack of a better term) level, we can look to the kinds of sound boards that audio engineers use. Or to vim used by programmers, and it’s myriad of commands. Or even to games, like World of Warcraft, once players bind every ability to a key on their keyboard (and aren’t clicking on icons anymore.)

Or even just a keyboard when you need to type a lot of text. Doing that on a phone or tablet is awful!

Already with just these two levels, I think people generally appreciate the difference. I’ve heard many people parrot the comment on how tablets are only good for consuming content, not creating it. And I hope nobody tries to write papers or essays on a tablet without a keyboard.

But once we get to the next level, linguistic communication, I think people seem to forget that lesson, or somehow think it doesn’t apply. Then we get Lab View and Excel, and all manner of other mistakes in trying to program by pointing and clicking. Somewhere along the line, I heard someone joke that you can’t do anything truly useful without language, as a caveman, solely by pointing and grunting. Well, you can (see above: surf the web! “useful”…), but I think when you need language, it is really and truly irreplaceable. When humans need to communicate with humans, we sure haven’t figured out anything better yet.

The trouble, of course, is that these things (like Lab View and Excel) have actually succeeded pretty well, and so I can’t be totally right that these are useless. But the trouble is not that they’re useless, it’s that they inevitably lead to horrible messes as a result. Multi-million dollar businesses relying on incredibly error-prone piles of crap no one wants to touch, and no one understands, is extremely common. We have entire research programs dedicated to trying to figure out how to mitigate this mess. And they have a “horror stories” link on their front page.

So I’m extremely skeptical of this sort of thing.

But let me point out one bright side: Scratch. It’s point and click programming. But there are two amazingly important differences between Scratch and other kinds of point and click programming I’ve seen. One: it’s still quite linguistic. Look at the front-page example. An event hook, a loop, and a series of commands. No you didn’t type all that in letter by letter, but you’re still pretty much writing in a language and kids get it. And two: it’s a stepping stone for learning, not an attempt to “make programming easier” or make programing “not programming.” This makes all the difference in the world. Nobody is going to try to build anything but toys for their own education with Scratch.

So here’s my tl;dr bit of advice for anyone trying to replace Excel, or whatever: you can have a Scratch-like learning mode for using your software, to make it easy to use for non-programmers. But the point of this shouldn’t be to “make programming easier” or wave your hands and claim it’s “not programming”, it’s to teach those users programming. Confront the hard problem straight on, and solve it. One day, they can turn that mode off, and then write their programs.

Oh and also, don’t make up a programming language that ignores everything we’ve learned about programming languages for the past 60 years. It’d certainly help us avoid a big mess if they’re not then writing programs in yet another poorly thought out undesigned language.

Posted in Programming | Tagged , | Leave a comment

The Fermi paradox… isn’t.

There is a common topic among people who like to think about the future and space travel: the Fermi paradox. Simply put, if you take even tiny-seeming growth rates for any civilization in the galaxy, it should be everywhere in the galaxy within a billion or so years. And there have been 14 billion years, so where are they?

The wiki page suggests quite a lot of possible explanations, many of them nonsense, unfortunately. But it’s worth questioning the very basic assumptions of the argument, rather than resorting to making up extra things to explain the problem away.

The paradox rests on a few foundations:

  1. Civilizations are at least relatively common.
  2. Civilizations survive.
  3. Civilizations expand.

There are several other totally non-essential assumptions that are sometimes made. For example, the whole bit about radio broadcasts in the wiki isn’t really relevant because radio won’t be detectable from background noise at any real distance. But it doesn’t matter, because given a bit more time, you’d expect them to simply be everywhere.

There are already ways to question the first two assumptions. Most of them somewhat implausible. Dystopian sci-fi is all the rage these days (possibly partly fueled by inaction on climate change), so blathering about civilizations destroying themselves is a popular. But I’m not such a pessimist. The sticking point is that even if most civilizations die off, well… the rest ought to be enough.

The trick of the paradox is that even if the numbers are tiny (1 civilization per million stars! 1 in ten thousand survive!), you multiply by a big number (times 300 billion stars = 30 civilizations), and you basically only need to get 2 for the paradox to work. There’s us, and there’s someone else, then given enough time, we ought to be everywhere.

But… I don’t see people question the last assumption enough. Why expand? Usually this is hand-waved away (if the expansion rate is only 0.00000001% per year! Wow so little!) but that’s not good enough. The number really could be indistinguishable from zero.

Here’s the UN population projections to 2100. If anything, I think these are optimistic, and they suggest a leveling off around 11 billion humans. This isn’t due to any sort of resource constraint. It’s entirely due to the birth rate falling off a cliff (in fact, going below replacement and we expect population to decline!) as soon as a population reaches a certain level of economic security and education (particularly for women.)

So, here’s a thought, if we top out at 11 billion humans, just what are we going to fill those 300 billion stars with?

There are of course some counter arguments. For example, what about AI? Or curing aging? But I think these too are dead ends. I’m not worried about AI, but that’s a topic for another post. As for curing aging… I predict it will lead to an even more severe drop-off in the birth rate. (You know the “ticking biological clock?” Yeah, why rush? Without that deadline hanging around…)

One can also object that maybe other species won’t be like humans in this respect, but… why assume otherwise? We don’t really have any reason to. I don’t think this objection is sufficient when we’re calling the problem a paradox. You don’t get paradoxes from unfounded assumptions. Just don’t make that assumption, problem solved.

Ultimately, I don’t think civilizations will expand beyond maybe a handful of nearby stars, and that’s iffy. (Depends on whether there are any real unpredictable existential threats that can hit a whole star system at once.) And the long term expansion rate will be determined only by the rate that stars die (the sun should be useful for another 8 billion years, even if the Earth isn’t. Why move before then?) Which means the growth rate is indistinguishable enough from 0 that the paradox is no more.

Posted in Futuring | Leave a comment

Programming is the new literacy

Chris Granger has a post ironically titled “Coding is not the new literacy.” It’s pretty good. Despite the early part where he attempts to redefine literacy in order to have a catchy title:

This is certainly accurate, but defining literacy as interpreting and making marks on a sheet of paper is grossly inadequate. […snip…] …composition and comprehension. And they are what literacy really is.

So if you ignore that bit, it goes back to, in effect, arguing that programming is the new literacy:

Reading and writing gave us external and distributable storage. Coding gives us external and distributable computation.

I think the probable source of his disconnect is that he’s working on Yet Another “hey, maybe people should program without actually programming, so let’s call it modeling and then make a gui to click on and,” and well, I don’t really need to know more, that’s going nowhere.

I’m definitely 100% on the side of programming being necessary to have any level of higher communication between human and computer beyond pointing and grunting. Language is the highest form of communication between humans and there’s no reason to believe this isn’t true between humans and computers as well.

The trouble for bringing programming to the masses isn’t that we’ve stubbornly insisted on writing code in a programming language as the way to do it. It’s that our languages, tools, platforms, and so forth are all basically crap. Programming is legit pretty stupid, and we have to put up with a lot of mistakes we can’t seem to actually fix. Mistakes piled on other mistakes, that require us to make still further mistakes.

Granger ends with referring to Alan Kay. Kay is someone I also agree with in the sense that he’s identified the right problem. Unfortunately, Kay is also someone I think proposes solutions (or at least, suggests directions in which to find solutions) that are… also quite incorrect.

Ultimately, I think this is the real issue. We don’t need prophets to tell us what the new One Correct way is. We need to be able to just fix our past mistakes. Just the ability to not be married to designs and ideas we invented 30 years ago, and realized were garbage 25 years ago, but still persist because we’re unable to change anything.

That’d be nice.

Posted in Programming | 1 Comment

More on Abstraction

Almost a year ago (evidently), I wrote briefly about Abstraction, Modularity, and Composition as important principles in designing software. I’ve had a few more thoughts to add about abstraction.

There are two sides to the abstraction “coin”: there’s (for lack of my knowing of any better terminology) pattern abstraction, and then there’s property abstraction. Each of these are simple enough to be illustrated with just the lambda calculus itself as an example.

What prompted me to write today was that I saw a claim that macro assemblers are really all-powerful and all these languages we’ve invented are “really” just macros piled on assemblers. This is, of course, bullocks.

This amounts, essentially, to the claim that the only abstraction that matters is pattern abstraction. Pattern abstraction is pretty much just taking commonly repeated patterns, and creating an abstraction with the varying parts as parameters. So, if we find ourselves iterating over lists of things often enough, we might go write:

apply f (h:t) = f h >> apply f t
apply f [] = return ()

And we’ve now abstracted away this iteration pattern, and we can now just write the function we want to run on each element of the list, and re-use the rest. Identify the pattern, and abstract it out.

Applying this to macro assemblers, and it amounts to the claim that class definitions and such from higher level languages only matter in the assembly code they cause to be emitted. The pattern is the only thing that matters.

But that’s not all there is to it. In particular, with our apply function. we’ve abstracted away an iteration pattern, but when can we use it? For such a tiny little two line thing, maybe this isn’t a big deal, we can just go read the code. But for bigger and bigger abstractions, “just read the code” isn’t good enough anymore. We could go read the documentation, but when we have more and more abstractions, “just read the docs” isn’t really good enough anymore either. Read what docs? Should we know everything about everything before we write any code?

We start to see the beginnings of property abstraction when we look at static types:

apply :: (a -> Action) -> [a] -> Action

(I’ve simplified this a lot, because I don’t want this to be about Haskell. Just read “Action” as a return type like “void” in C, where the point is to have side effects, not actually return something.)

Before, we could look at that pattern in a purely untyped way. We could pass anything into it, and the only way to know what would happen is to run it (or at least, simulate running it in your head.) But now we know some properties about the function, and about its parameters.

Abstractions always have an “outside” and an “inside” and both matter, and both have properties we’re interested in. An “abstraction” is not merely a repeated pattern like “apply”. It’s also something we’re holding abstract about which we know some properties, like “f” within apply. (And in some sense, “apply” for the rest of the program.)

My point of this isn’t that static types are great, or whatever. It’s that properties are great. The more we actually know about the stuff we’re working with, the less horrible programming is.

I think “property abstraction” is the main reason that, for example, Java has succeeded, while Lisp has languished. Everyone likes to make fun of Java, but despite its flaws, I do think it’s a good thing that, in Java, everyone knows it’s just plain not possible for an object to suddenly mutate what class it is. Lisp advocates go on about the “power” of being able to do something like that, but I think they’ve forgotten the “power” of knowing that sort of thing can’t happen to you. (Ditto Python vs CLOS, if you want an example without static types.)

Anyone who thinks languages are just macro assemblers is making the same mistakes. They’re looking only at the patterns, and not the properties.

Posted in Uncategorized | Leave a comment