JavaScript, Swift, and Kotlin Oh My!


Apple II User's Guide book cover

In the 1981 I cracked open my first real book on computer programming: Apple II User’s Guide by Lon Poole with Martin McNiff and Steven Cook. I still have it sitting in my bookshelf 36 years later. Previous to the Apple II User’s Guide I was playing around with typing-in game and program code from hobbyist magazines like Compute!

But now I felt ready to write an original program. I had no education in Computer Science, and I didn’t own an Apple II computer. But armed with the information in the Apple II User’s Guide I knew I was going create a original program. What that program would do was not as important to me the process of actually doing it. After several decades in software engineering, I still feel the same way. I don’t care much what my programs do (now we call them apps or services). I care very much how they are built and the processes and tools by which they are built.

Two of the chapters in the Apple II User’s Guide are about the computer itself and how to use it. The other six chapters and appendices A through L are all about programming. Which, at the time, made a lot of sense. Unless you had a business of some type, the main purpose of using a general purpose personal computer in the 80’s was programming it. Otherwise it was an or overpriced home gaming system.

In 1981, the main and as as far as I knew only, programming language was BASIC. The idea of BASIC is summed up by expanding it’s acronym: Beginner’s All-purose Symbolic Instruction Code. A simple, high-level programming designed for teaching newbies how to code. Unfortunately for me, BASIC didn’t do well what it was designed to do.

I read the Apple II User’s Guide from cover to cover. I highlighted passages on almost every page. But I never did write that original program for the Apple II.

BASIC as in the 1980s was a much simpler and unforgiving language than the programming languages of today. Some versions of BASIC only supported Integers and almost all limited variable names to only two significant characters. Lower-case letter were not supported. Features programmers take for granted today, objects, classes, protocols, constants, and named functions didn’t exist. The core features BASIC did have were strings, arrays, conditionals, loops, simple IO, and the ability to jump to any line in code by it’s number.

None of our modern tooling was available on an Apple II back then. Instead of an integrated development environment you had modes: immediate, editing, and running. Basic programs were written with numbered lines and you had plan out the construction of your code such that you left enough room to add lines between groups of statements or you were constantly renumbering your code. As the Apple II guide notes on page 51, “The simplest way to change a program line is to retype it.”

BASIC programming code

Debugging was particularly hairy. Programmers had only a handful of primitive tools. The TRACE command printed the code as it executed. The DSP command printed a particular variable every time its value changed. Whatever the MON command it, I never could figure out to work it properly. So like most hobbyist programmers of the day I used print statements littered through my code to check on the state of variables and order of execution of the subroutines. A simple and reliable technique that works to this day.

Like I said, I got so caught up in the complexity of programming an Apple II in BASIC that I never wrote a significant original program for that machine. (Later I would figure it all out but for the cheaper home computers of the 80’s with more advanced BASICS like the TI99/4a and the Commodore 64.)

Looking back on it, without modern programming languages and modern tools and most importantly without the web, YouTube, and Stack Overflow, I honestly don’t know how I learned to program anything. (But I did and where it took me is a story for another time.)

Today we have the opposite problem: Hundreds of programming languages and tools to choose from and hundreds of platforms upon which to program. Apple alone has four operating systems (macOS, iOS, tvOS, and watchOS) and supports three programming languages (C/C++, Objective-C, and Swift). Google has Android, Chrome, and Google Cloud on the OS side and Java, JavaScript, Python, Go, DART, and now Kotlin on the coding side. Microsoft, Facebook, and Amazon all have clouds, platforms, and a rich set of programming languages.

And then there are hundreds of communities centered around boutique programming languages. My favorites include Elm, LUA, and LISP. (By the way, it was LISP that taught me truly how to program. Learning LISP is the best thing you can do if you don’t have a computer science degree and you want to punch above your weight.)

In 1981 my problem was learning one language on one machine. In 2017 there are so many combinations of programming languages and platforms that it can seem like an O(n!) problem to sort through them all! Most engineers today need to learn JavaScript, HMTL, CSS, PHP, and SQL to program on the web, C++, Java, C#, or Go for hardcore backend services, and either Java or Objective-C to create native mobile applications. Plus it’s really important to understand several UNIX commands, a few scripting languages like Python or Perl, and tools like GIT, Xcode, Unity, Visual Studio, and Android Studio. At least I seem to need to understand the essentials of all of these in order to tackle the general sorts of programming challenges and opportunities thrown my way.

Yikes! 😣

In the last few years, the major players in the world of technology seem to be converging towards a programming language mean. While BASIC, LISP, and C++ were once very popular and are very different, the newer programming languages seem to be very similar.

JavaScript started this tread by adopting the features of strongly-typed, object-oriented, and functional languages, while keeping its boilerplate-free syntax. JavaScript has become the BASIC of the modern era–Easy to learn and widely available. JavaScript used to be a terrible programming language. One of my favorite books, JavaScript the Good Parts, spends most of its pages on the bad parts. But JavaScript is evolving rapidly with the ECMAScript 2016 standard, dialects like TypeScript, and platforms like Node.js.

Apple and Google seem to be noticing how powerful and yet accessible JavaScript is becoming. Instead of adopting JavaScript for their mobile platforms they are doing something almost as good: Creating and supporting JavaScript-like languages.

Apple started this trend a few years back with its surprise introduction of Swift. At first the Apple programmer community was a bit miffed. After decades of working with Objective-C and it’s highly idiosyncratic syntax, Apple seems to be abandoning billions of lines of code for a pretty but slow and immature language that had just sprung into existence unasked for and unneeded.

Except that something better than Objective-C was needed. The bar for programming Objective-C is very high. And it’s only used in the Apple universe. So it was hard to learn to code iOS apps and hard to find programmers that are expert in iOS apps.

Most importantly Apple rapidly evolved Swift, much to the horror of many engineering managers, so that the Swift 3.0 of today is an expressive general purpose programming language and a model for where JavaScript could go.

At Google IO, just a couple of weeks ago, Google, perhaps out of Apple-envy, surprised its programmer community by announcing “first-class” support of Kotlin. Until that announcement the Android world revolved around Java and C++. While Java and C++ are more mainstream than Objective-C they still represent a cognitive hurtle for mobile programmers and created a shortage of Android developers.

Kotlin, one of the many interesting JVM languages, compiles to byte code and feels much more JavaScripty in its expression. Android programmers were already using Kotlin but with Google’s official blessing support in Android Studio’s and other tools is going make using Kotlin easier for beginners and experts alike.

So the web, Apple, and Google are converging on a programming languages that are similar but not exactly the same. Where are they going?

Here are three bodies of code. Can you spot the TypeScript, Swift, and Kotlin?




While these are not very sophisticated lines of code, they do show how these languages are converging. (A is TypeScript. B is Swift. C is Kotlin.)

In the above example the first line declares and defines a variable and the second line prints it to the console (standard output).

The keyword let means something different in TypeScript and Swift but has the same general sense of the keyword val in Kotlin. Personally, I prefer the way Swift uses let: it declares a variable as a constant and enforces the best practice of immutability. Needless mutability is the source of so many bugs that I really appreciate Xcode yelling at me when I create mutable variable that never changes. Unfortunately Kotlin uses val instead of let for the same concept. Let in TypeScript is used to express block-scoping (which this variable is local to the function where its is declared). Block-scoping is mostly built into Swift and Kotlin: They don’t need a special keyword for it.

Just from the example above you can already see that jumping between TypeScript (JavaScript), Swift, and Kotlin should be pretty easy for the average programmer and more importantly, code should be pretty sharable between these three languages.

So them why are JavaScript/TypeScript, Swift, and Kotlin so similar?

Because programming as a human activity has matured. We programmers now know what we want:

  • Brevity: Don’t make me type!
  • No boilerplate: Don’t make me repeat myself!
  • Immutability by default and static typing: Help me not make stupid mistakes!
  • Declarative syntax: Let me make objects and data structures in a single line of code!
  • Multiple programming styles including object-oriented and functional: One paradigm doesn’t fit all programming problems.
  • Fast compile and execution: Time is the one resource we can’t renew so let’s not waste it!
  • The ability share code with the frontend and the backend: Because we live in a semi-connected world!

There you have it. Accidentally, in a random and evolutionary way, the world of programming is getting better and more interoperable, without anyone in charge. I love when that happens.

A Short Note on Tolkien’s On Fairy Stories

I’ve been a fan of J.R.R. Tolkien’s Hobbits and Middle Earth since I first ran into Bilbo Baggins at a children’s library appropriately as a child. I remember falling in love with the tale and being somewhat disappointed that the other books of its type were not as deep or as rich as Professor Tolkien’s work. As I was a little kid, I could not articulate that disappointment. I only felt a general sense of something lost when the book was over, and no other book on the same bookshelf return it to me: not Wind In the Willows, not Charlie and The Chocolate Factory, and not even the Wizard of Oz. All great books but even a child I connected with some inner meaning inside the Hobbit that stood on its own and seems as real and primary as the mundane world in which I lived.

I’ve been on a quest, as it were, to find that something, which continues to this day. It’s present in all of Tolkien’s works, from the Lord of the Rings to the Silmarillion. I’ve found it in more recent works aimed at kids, including J.K. Rowling’s Harry Potter and Pullman’s His Dark Materials. But there is much more of that something in classic Science Fiction. Asimov’s Foundation has it. Gene Wolf’s The Book of the New Sun has it. Iain M. Banks’ Culture has an especially strong dose of it. The best works of Stephen King and Agatha Christie have it. So, this something is not constrained to Fantasy or Scifi. Even works of non-fiction, such as Yuval Noah Harari’s Sapiens, is strongly infused with whatever this something is. Heck, even philosophers like Plato, Wittgenstein, Heidegger, and Bernard Suits talk about it.

I’m really name checking here, but whatever this magic is it’s really quite rare, difficult to express, and almost impossible to capture. It’s a uniquely human product and shows ups unannounced and uncalled in works of art, musical compositions, theatrical productions, motion pictures, essays, and books of all flavors and genres.

This magic is a specific something, not a general feeling or vague concept. But you feel it in your bones while comprehending it with your head. It’s not the cheap tug of pity on your heart strings or the slight-of-hand of flashy conjuring trick. Artists, writers, doctors, lawyers, scientists, directors, actors, podcasters, and even computer programmers deliver it unreliability and it somehow speaks to us universally.

Personally, I believe the modern master of this magic something is Neil Gaiman and is present in everything he has ever written but no less or more so than his masterpiece American Gods. (I’m not sure yet if it’s presence in the TV series).

For me been impossible to define and yet instantly recognizable.

What is this mysterious, universal, sometime that I first glanced at as a child and I’ve been chasing ever since as a pastime. It’s mere escapism? It’s a misguided religious impulse? Is it a sense of meaning and inner coherence that the so-called real world of random punctuated equilibrium is sorely lacking?

Image how utterly stocked I was to find that Tolkien, the master himself, defined this magic something simply and plainly, in an essay entitled On Fairy-Stories written in 1939. An essay hadn’t read until this last week!

Before I go into a few key points that Tolkien makes in his obscure essay let me explain how I found it (or it found me).

I love a good podcast. And by good, I mean folksy, intimate, and long-winded. Since podcasting became a thing, thanks in large part to Sara Koenig’s Serial, many podcasts have become indistinguishable from mainstream radio productions. But these are not good podcasts. The quality of a podcast is inversely proportional to the its production values.

The great podcast are exemplified by Philosophize This!, The History of English Podcast, and The History of Rome.  Each of these is the efforts of lone amateur, a self-made wonk that a professional media outlet would never hire, using a home-made studio, for whom money is an urgent secondary concern, and for whom her primary concern can only be expressed by rambling on about her chosen topic out of passion and an imperative to share.

One such podcast is There And Back Again by Point North Media, which I’m pretty sure is the DBA of one guy: Alastair Stephens. There And Back Again is a deeply detailed look at Tolkien’s works, starting in chronological order, and planned to run for several years. Each podcast is a recording of a live online lecture where Stephens interacts with his fans on Twitter and YouTube while trying to get through his analysis of Tolkien’s works. Most of these podcasts are over an hour long and Alastair often spends 30 minuets discussing a single sentence! This untidiness is the hallmark of a great podcast: It’s here in the earnest solo confabulation of the caster that you get insights and gems that you would otherwise gloss over or never hear in more edited, polished production.

The brightest gem for me was Stephens exploration of Tolkien’s essay On Fairy-Stories. During four decades of loving Tolkien I didn’t know this essay existed. Remember, my search for the magical something that Tolkien brought to life inside me is a pastime not my mission. I’m not actively searching. Mostly, I’m filtering through the bits of information that pass under my nose in the normal course of living life and flagging anything that might smell of the something for later analysis.

You should stop now and read On Fairy-Stories. It won’t take long… (I linked it again so you don’t have to scroll up!)

So, what did Tolkien say about fairy-stories that helped me, and hopefully you, understand what this magic something is?

First, Tolkien reveals that the dictionary is no help in defining a fairy-story. This observation, I believe, is an admission that Tolkien is inventing the idea of the fairy-story, right here, in his essay. Before Tolkien, the fairy-story was a fairy tale and didn’t consistently contain the elements that Tolkien feels are essential. This is a pretty brilliant rhetorical technique of bending outer reality to inner concept by claiming the authorities and the collective culture of humanity didn’t get it right!

Second, Tolkien argues against the idea that fairy-stories are for children and that fairies in fairy-stories are little people. Tolkien assures us that children can gain something from fairy-stories in the same way adults can–by reading them and becoming enchanted. This idea of enchantment is different from the willing suspension of disbelief. Tolkien points out that you have to believe in the primary world for a secondary world to take hold. Note: there is a subtext in the essay that the primary world is the original, and that we, the thinking creatures of the primary world, are sub-creators, creating secondary worlds. And further, that this is humanity’s role in the cosmos because we have the power to create names. Tolkien was famously a Catholic, in a Anglican country, and it shows in his idea of primary and secondary worlds.

Tolkien wants his fairies, which he calls elves, to be as large of humans, because they are peers of humans. While he doesn’t point this out in the essay, humans, alone of all animals on planet earth, have no peers. We have only ourselves to talk to. Until the day we make contact with intelligent alien life, elves are as close as we can get to another species with a second opinion on the universe–even if we have to invent them in our imaginations!

Third, Tolkien goes on at some length to discuss the origin of fairy-stories and touches on the ideas of invention, inheritance, and diffusion. His main point is that a story always has a maker. He doesn’t mean owner, or even author. He means that at some point in time, some person first told that story which was then retold by other people, and changed in the telling, until we get to the fairy-stories we have today. The important point, for me, the recognition that fairy-stories are created, artificial objects. The critical something, that is at the heart of all true fairy-stories, was originally place there by a person. Fairy-stories are the products of people.

Fourth, Tolkien defends the fairy-story from the criticism that it is mere escapism. In a brilliant bit of reasoning Tolkien explains that those disapproving of fairy-stories are confusing them with entertainment that allow us to “desert reality”. Tolkien notes that it’s not fair to condemn the prisoner for “wanting to escape a prison”. Amen Brother! Plato, Wittgenstein, Heidegger, and Bernard Suits all agree with Tolkien on this point!

The human condition, which we all share, is the struggle with confinement of our culture, our class, our race, our gender, and our environment. The one problem poor and rich, liberal and conservative, all the races, and all the genders share is the fact that we are impression in temporary shells of flesh and the opinion we hold against each other (Sartre: “Hell is the other people”). The magic, mysterious, hidden, indefinable something, buried deep in the heart of a fairy-story, gives us a temporary escape into enchantment and the opportunity to bring a bit of that something back from the secondary world into the primary world. We get a chance to improve the human condition!

Fifth, Tolkien observes that the world of the fairy-story is just a reflection of our primary world. A reflection where mundane meaninglessness becomes strange and meaningful. Tolkien talks about the beauty of candlelight and ugliness of industrial age electric street lamps. I don’t quite agree with him as industrial age electric street lamps is now a whole esthetic (Steampunk) and not considered ugly. Tolkien and I generally part ways on this point, which is a present theme in all his books. that any technology more complex than 18th century farming equipment is unpleasant at best and an agent of evil at worst.

But I think there is a more profound insight here, that there is a platonic beauty that can only be discovered by looking at our primary world though the lens of a secondary world. Not a distortion but a focusing on the details that we’re taking for granted.

Tolkien expresses this idea of platonic beauty, which to mortal eyes is both lovely and dangerous, with the concept of Mooreeffoc. This term is new to me, but the concept is not. Moreeffoc is the word “coffeeshop” written on glass as seen from the wrong side.  It’s the idea that the fairy world is right in front of our noses, if only we could see it.

Sixth and finally, Tolkien invents a new term for the happy ending and explains that happy endings are crucial element of all fairy-stories. Tolkien’s word is Eucatastrophe, which means a joyous turn of events and is easily mistaken for Dues ex machine. In the Great Fairy-Stories, those written by Tolkien, Rowling, Gaiman, Freud, and Thomas Jefferson, the happy endings are not specifically happy, and cheap plot devices are not at work to bring about a sentimental conclusion.

When Frodo is about the toss The One Ring into the fires of Mount Doom, loses his battle with the Ring, and cannot bare to complete his mission, Gollum (spoiler alert), bites off Frodo’s finger and leaps, or falls, into the lava finally destroying the Ring.

The power of that eucatastrophe is that the War of the Ring has been lost at the final moment. All the struggle has been in vain. There is truly no turning back and no way for the cavalry to arrive. Evil has clearly and completely triumphed.

But then, after defeat has been realized, an unexpected and unasked for agent makes a supreme sacrifice and saves the day. Best of all, Gollum, is acting in character, he is not an obvious agent of good or the divine, and he has no intention of saving the day! He doesn’t have a change of heart of discover the good inside him. Gollum just wants his damn ring back!

In The Hobbit, Bilbo reframes from killing Gollum. Bilbo should kill Gollum. Gollum is scary, dangerous, sick, and twisted by evil. In a 21st century video game Gollum is exactly who it’s OK to kill. By all measures of human justice Gollum is the type of person you should kill–or at least lock up forever.

But Bilbo, this silly, almost powerless, hobbit doesn’t kill Gollum. Bilbo reframes, not because he isn’t in fear of Gollum, but because Bilbo is a hobbit, and hobbits don’t kill people. Hobbits are not heroes.

In the finale of the Lord of the Rings, this humble act of not killing, which seems foolish as Gollum a danger to Frodo, this is the act that saves the world.

And that is the something I first glimpsed as a child and now understand as an adult.

The ending of the Lord of the Rings is far from sweet. The hobbits and the world around them is saved but scarred and is eventually destined to fade. However, the core values of Middle Earth remain intact.

We’re all destined to fade. We can’t protect ourselves or our children completely from evil. We live a real, primary world, not a fairy-story or a utopia. But we can venture into secondary worlds, which in my book includes political theories and scientific models as well as works of fantasy, and bring something valuable back.

In this world, every day, a Bilbo is not killing a Gollum, and years later, at the last minute, a ring of power is destroyed and the world is saved. These moments are not usually televised and don’t make for viral new headlines:

“Father reframes from slapping son and later son remembers this and reframes from assassinating president in 30 years.”

“Memory of mother’s love prevents terrorist from blowing up building in city center 20 years laster.”

“Friend randomly calls friend on a Saturday night and prevents suicide planned for that evening.”

“Guy buys homeless man a cup of coffee at Penn Station and the probability of nuclear winter replacing global warming reduced by 1%,”

There are many names for these moments of empathy but I didn’t have a great name until eucatastrophe, a good disaster.