Perl and Me, Part 5: Speaking with the speech of coders

This is part 5 of an ongoing series where I explore my relationship with Perl.  You may wish to begin at the beginning.

This week we look at Perl’s linguistic heritage.

Last week I talked about how good code reads like a story, and how Perl is the best language for writing stories in code.  The reason for this is of course the linguistics that are baked into Perl.

I always knew that the creator of Perl had more than a passing grounding in the field of linguistics.  Even if this had not been part of the Lore of Larry (and it is), I could have probably guessed it just from the structure of the language.  Almost all languages have nouns and verbs, but Perl has indirect objects, and adverbial clauses, and a concept of singular and plural.  More than anything else, it has context.  Context, which is so vital to and ingrained in our natural langauge that we aren’t even aware of it most of the time, is often missing from computer languages.  Context, you see, breeds ambiguity, and most computer languages avoid ambiguity like the plague.  Not Perl.  Perl embraces ambiguity as the price of having context, and context as the price of—more accurately, as integral to—expressiveness.

So I was aware that Larry had studied linguistics in college, but not much more than that.  But a few years ago, Big Think did an extended video interview with Larry.  It’s 45 minutes long, but they’ve also thoughtfully edited down some smaller videos focussing on specific topics.1  The part that focuses on the linguistics of Perl is a brisk 6 minutes, and well worth your time.  Let’s look at some of the highlights.2

... the design all along has been to pull things together in almost a random way, the way in natural languages, you know.  English pulls stuff from Viking and French and Anglo-Saxon and what have you, even a little Japanese here and there—a skosh.3  But the way a natural language is put together like that always fasicnated me ...

In other words, Perl is syncretistic.  It steals stuff from other languages and jams them all together, and it reconciles them.  It makes them all fit together seamlessly ... or more or less seamlessly.  We can see the seams a bit when it comes to OOP, as we’ve discussed before.  But we’ve also seen how things like Moose, and then declarative systems like MooseX::Declare or Moops or p5-mop, can also get jammed into Perl and reconciled along with everything else, which helps smooth over the seams.  If you read LeoNerd’s Futures advent calendar, you can see yet another example of Perl syncretism at work.  It’s easy to extend Perl in this way because it’s like a natural language, and this is how natural languages evolve too.

Of course, evolution can be messy, and Perl often takes heat for this.  As Larry says:

You get dialects.  You get languages that get smushed together so you get creoles and pidgin languages.  And you get languages that you think ought to be understandable to two different people, but they aren’t.  You get languages that have the same name, but are different from each other.  You get languages that have different names, but are really essentially the same language.  So all the processes that happen as natural languages evolve, through time, happened in computer languages, too.

The implication for Perl is that any two given Perl programs might not look very much alike.  I mentioned last week that I found reading RJBS code to be a bit like reading A Clockwork Orange.  Another analogy one could use is that it’s a bit like reading a PhD thesis.4  Such works can be very dense, and often require bactracking and rereading before you get the hang of the language.  So why are they written that way?  Because, after you get the lingo down, it’s the most efficient way to communicate complex ideas.  And so it is with RJBS code, or code by The Damian, or Ingy code.  It takes a certain amount of time to parse the dialect.  But, once you do, you find it’s been well worth your time.

Of course, not everyone agrees with this statement.  Many people find that having every different Perl program read differently is confusing.  They like simpler languages, that enforce only one way to say each thing.  Such languages are easier to teach, they point out.  Which is true, I suppose.  I’m just not sure that it should be the primary attribute for a computer language.

Many non-native speakers say that English is quite difficult to learn as well.  So should we not speak English any more?  Well, there goes Shakespeare.  I personally found French a bit difficult when I tried to learn it; should we abandon that too?  No more Victor Hugo then, which puts a serious damper on the American musical spectacle industry.  If German’s too hard, we lose Goethe.  Chinese seems pretty hard, with their thousands and thousands of characters, so I guess we’ll throw out the Tao Te Ching and The Art of War.  I could go on, obviously.

And, of course, I don’t find English difficult to speak at all.  It was probably tough for me to learn, once, but I don’t really recall that.  Even people for whom English isn’t their first language don’t find it that difficult after the initial learning curve, in my experience.5  Perhaps their English is simple at first, but they get the message across.  And, the more experience they have with it, the more sophisticated and nuanced their communication becomes.  This mirrors our experience learning Perl: some people find it tough to learn at first, with its different sigils for different variable types, its funny way of passing arguments to functions, and its strange variable names like $_.  But it’s not really that hard to speak “baby Perl,” and a hell of a lot of programmers have managed it over the last quarter of a century.  We start with simple communication, then we become more sophisticated, expressing more and more complex ideas.  Many things that are very rewarding weren’t easy to do the first time we tried them.  But we stuck with them, and now we’re glad we did.

On the all-important topic of context, Larry says:

So there is a scale of how much a computer language resembles human language in, primarily based on how much context is involved.  If there’s very little context, it’s very literally—there’s some computer languages that are like that.  And then other languages know a little bit more about, you know, what has been stated earlier in the program, or what the immediate surroundings are in the program, and Perl kind of takes this to more of an extreme, not as far as human languages, because no computer is smart enough to understand human speech in that way (yet).

This gives us the answer to the question of why Perl does these odd things—having more than one way to do it, having different ways to say the same thing and having the same construct act differently sometimes—it’s context, and as much of an extreme as Perl takes context to, it’s nothing compared to how much natural language relies on it.  Human language has been evolving for tens of thousands of years, and it has evolved to rely on context for maximum expressiveness.  It certainly could have evolved to be simpler to learn ... but it didn’t.  It could have evolved to radically reduce ambiguity ... but it didn’t.  Human speech has become very good at facilitating communication and shared understanding between often disparate speakers, and it has done so, I would argue, not despite the burden of context, but because of it.  Many literary devices rely on ambiguity or contextual connotation: puns, double entendres, word play, metaphor, allegory.  The entire field of poetry would be in serious jeopardy without context.  Context sensitivity doesn’t decrease clarity or understanding; often, it enables it.

So, as an English major and aspiring writer, is it any wonder that the language which most attracts me is the one that seems the most expressive? the one that allows me to write the best stories?  One final quote from Larry’s interview:

... but if a computer language is well designed, the computer language designer stays out of the face of the programmer and gives the programmer ways, various ways of having the flexibility that they would have in natural language, to pick one way of saying things or another.  And to the extent that they can give that flexibility, sort of give an artistic medium to the programmer to be creative, to that extent, people can take great joy in writing a computer program in the same way they might take great joy in writing a poem or a play.

Creativity is exactly what attracts me to Perl.  I wrote stories as a kid because I needed to create things, and that was my medium.  Now I create programs, and I’m just as happy, because I’m still writing stories, in my own way.  And because Larry Wall has given me (all of us, really) a gift: a language that not only allows my creativity, but encourages it.

So, sure, that makes Perl great for me.  But is creativity really good for all programmers?  That will be our exploration next week.

1 And a big shout-out to Perl TV for bringing these videos back into the spotlight recently.

2 All the quotes in this article are from this 6 minute snippet.

3 This is a linguistic in-joke, as the common etymology of “skosh” traces it back to the Japanese word “sukoshi.”

4 I’ve occasionally referred to the dialect of English commonly found in PhD papers as “PheeDish.”

5 And I don’t mean to ascribe any special powers to English here; I think this is true of non-native speakers of any natural langauge.


Thanks for this great post series. It makes me realize why I love Perl although I remember I had such a hard time to learn it at first (programming CGI's back in '98). And why other languages feel a bit ... dull while writing them (I'm thinking about Python and Ruby which I use, like, but do not *love*). And programming without pleasure and motivation gives dull programs.

Thanks for a great post! I'm a linguistics geek myself. One thing about Perl that is very languagey to me is the way it binds our community together. We create and share idioms. Certain styles and usages ebb and flow. There are prescriptivists and descriptivists. There are native great works, and a lot of translations from other languages. Our homeland is CPAN. I'm glad to be speaking a living, evolving creole instead of, say, Boeing Simplified English.

Would a language with exactly one way to say things be a monolect?

Leave a comment

About Buddy Burden

user-pic 14 years in California, 25 years in Perl, 34 years in computers, 55 years in bare feet.