Friday, June 18, 2010

Letter to a Young PL Enthusiast

(I wish someone had written this letter to me years ago.—Ed.)

Dear young programming language enthusiast!

You are fascinated by programming languages. You can not not program. But all the existing languages give you woes.

The mainstream languages like Java are horribly verbose and inflexible. C is much too lowlevel. C++ is much too big. C# hails from the evil Northwest.

You've dabbled in O'Caml and Haskell, but their type systems, which no one – not even Oleg – fully understands yet, restrict you.

Smalltalk and Self are cool, but forever hampered by their closed-worldness. JavaScript is teh suck like assembler with hashtables. Broken hashtables.

Scheme is cute, but its users are weird – before they start programming, they build a record system out of conses. Every goddamn time.

Common Lisp is cool, but its baggage is legendary. Whatever implementation you choose, be assured that it has been hacked on since you were a small child and has more comments saying "kludge" or "fixme" than the Plan 9 kernel has LOC.

Factor sure is nice, and Slava is rightfully annoying the hell out of other dynlang implementors, but its Forth legacy means you have to write your expressions in the wrong order.

Python and Ruby, what shall I say, they have the right idea, but their messed-up-ness is legendary. Perl is a sick joke. You don't want to stay with those.

Clojure and Scala have nice ideas, but they're unproven, and they run on the JVM, a messy enterprisey bore, that contains at least seven different implementations of hashtables.


Now that we've reviewed some of the popular languages out there, let me tell you: you must create a programming language, or be enslav'd by another man's.

But don't just go forthe and put whatever features you can think up into it. History shows again and again that the fools who do this cause more harm than good. Think: a programming language is much more powerful than a mere application in fucking people's brains up, and the programming world is already full of braindead zombies. You don't want that responsibility.

Go study all languages you can find. Try to understand where they come from, and where their good ideas end. (Don't try to understand Beta, nobody does.)

Ignore the siren calls of the virtual machines. You have to be the master of your domain. Use C or assembler to implemente your language. The free Unices are your friends. Learne about the internals of your operating system, how it compiles, links, loads, and runs executables, the fruits of your labor. Learn about calling conventions, system calls, and the god-given hierarchy of the memory.

Write a compiler, not an interpreter, for in an interpreter, you will always find an easy way to cheat yourself out of the labyrinth, and you will never have to face the cold, hard walls of reality and triumph over the Minotaur.

Don't be a slave to syntax. Syntax is the Maya of programming, forever blinding many of the weaker souls to the eternal light of symbolic expressions.

Understand the closure and the lexical address before you embark on your journey, lest you putte more bitterness into this world. Employ the power of the generic function – its ad-hoc polymorphism will forever bring you joy. Harness the flexibility of optional, keyword, and rest parameters.

Learne that all control flow is one, but weigh carefully whether to heed the seductive call of the current continuation. It will make your stack messy like spaghetti and thorny like a cactus. Learne to love the one-shot continuation, the unwind protection, and the tagbody, all willing and able to help you jump around as you please, safely and nimbly.

Don't obsess over raw speed like the hare. In this day and age, many a program spends most of its time in system calls, and you can always escape to a lower-level language if needed. But don't ignore performance either. If your runtime uses lots of associative data structures, or unneededly thrashes the precious caches, it will surely be slow as the tortoise, and you'll be the only one to blame.

Build a dynamic language, that flows like water around the rigid rocks of staticity, but don't ignore the limitless wisdom that comes from studying type systems. As St. Ehud said, types are predicates that hold true for the whole runne of your programme, and ye shall seek them everywhere.

Picke thy battles. Try to make your language the best one in a narrow valley, and then follow it to whichever wide open foreign shores it takes you. (But stay clear of the cape of cursor addressing.)

Learne how to documente and speak about your language and make it crystal clear in the minds of your fellow men – its syntax, its semantics, and its pragmatics. Take a bow to the great language manuals and texts written before your time, and seek to do even better than they did.

Scale the reflective tower of macroexpansion, even if it seems unsurmountable at first, and employ it in your language, to the neverending delight of your users. Make sure that thy macros are hygienic and referentially transparent, lest thy users dirty their hands and languish in the darkness of referential opacity. Learne about the art of the metaobject protocol, for you'll be a better programmer ever after.

Learne by heart the holy CLHS and the holy RnRS, and recite their sutras daily. They have answers to most of the questions you don't even know yet. Use SLIME daily to teste your knowledge. Follow the confident footsteps of Common Lisp and Scheme, most merciful, most compassionate, whenever the wind of uncertainty blows snow and ice in your path.

Finally, rejoice in the wisdom of the prophet Alanius Perlisius. His epigrams will lighten the load you have chosen to take on your shoulders. His words will forever be with you:
``What you know about computing other people will learn. Don't feel as if the key to successful computing is only in your hands. What's in your hands, I think and hope, is intelligence: the ability to see the machine as more than when you were first led up to it, that you can make it more.''

Dear friend!
I hope this shorte letter will help you on your longe path. May the language you will undoubtedly build delight the world with its absence of nonsense, the gravitas of its design, its joyful voice, and the pleasure and clarity it brings to the fabulous and mysterious act of programming.

Yourse,
X

P.S. Don't forget to put restartable conditions into your language. They are the best thing since sliced bread (and the anti-gravity space pen).

18 comments:

Rajesh said...

I actually enjoyed this blog post. As I reflect, the sad part is that I actually knew most of the language names, and your poetic interpretation of their nature.

Anonymous said...

1) You're wrong about Perl. 3) Gray fonts on a black background is annoying as fuck. Almost impossible to read.

Manuel J. Simoni said...

@Anonymous I am taking the liberty to continually diss Perl, because Larry continually disses Lisp, while building a language that takes huge parts of inspiration from it, which I think is unfair.

I should put that in a disclaimer somewhere.

And Perl does suck hard qua language, but I still respect it for its utility.

Re the fonts: Sorry, but you'll have to turn off the style sheet.

Anonymous said...

The styling is fine.

alexleverington said...

What would you say of Lua and Objective-C?

Just curious.

Manuel J. Simoni said...

Lua is definitely on the well-designed end of the spectrum, the VM is small and elegant, and the performance of LuaJIT is simply awesome. In fact, having an implementation that's as small and performant as Lua's is one of the challenges I have set myself for my next language.

I know next to nothing about Objective-C.

Udyant Wig said...

Which assembly language/CPU instruction set would you consider well-designed?
I've read that:
* 6502 is good
* x86 sucks
* RISC is cool/better
* PDP-10 is great

Manuel J. Simoni said...

Sorry, I've no idea (I'm focusing on compiling to C atm), but I've heard roughly the same thing.

Anonymous said...

Great post!
Thank you : )

patrickdlogan said...

Motorola 68000 was a nice instruction set.

patrickdlogan said...

Compile to Gambit would be pretty easy as at least an initial implementation.

Manuel J. Simoni said...

Patrick, I've compiled to JavaScript in the first iteration, but now I'd like to move one level lower. And it's already much more fun. :)

Mathnerd314 said...

Thank you for this post; it is very helpful for a young PL enthusiast like me. :)

Aissen said...

What do you think of Go ? And Vala ?

Manuel J. Simoni said...

Commander Pike is one my big heroes, so of course I'm interested in Go. I haven't seen a lot of interesting stuff in it yet (which is good, in a way – using Go shouldn't be surprising and I like that). One thing that bothers me slightly about it is that the authors seem to live in a bit of a bubble. For example (one of my pet peeves, so watch out ;)), resumable exceptions are the bee's knees for handling all kinds of (abnormal) situations, interactively or programmatically. That's simply a fact. And Go doesn't even have ordinary exceptions, AFAIU. Instead they go for some unproven new thingy, which IMO only adds confusion.

Goroutines sure are nice. And given that Go will probably find many users, and is driven by a couple of high-profile people, it surely is one of the most interesting new languages to watch.

I haven't heard of Vala, but I'll take a look.

Tim said...

What do you think of Nasal? Io? Simula? AWK? Tcl?

omega said...

This post was really hard to understand but I agree with your opinion to start programming with C/C++ and nothing but C/C++ - if you really want to learn a language that is hard to read (write-only language).

In my experience the way that Konrad Zuse thought about programming was somehow more appealing to me and I think that Plankalk├╝l ist the most interesting language to start with.

The quest to write a compiler is somewhat unnecessary to take the burden of, because there is a much better way to destroy your mind: thinking of XPath as a programming language and compile XPath queries into SQL statements.

So and what do you think of APL?

missingfaktor said...

"but its Forth legacy means you have to write your expressions in the wrong order."

Have you actually programmed with Factor?