Today we close out our formal exploration of the stuff of programming languages. This is what we said we’d look into in the syllabus:
We started the semester by poking at the shell with its uni-type system, where everything’s a string and programs are functions that we can chain together in a very functional style. Then we investigated regular expressions as a language for expressing languages. From there we entered into a discussion of types, a feature that is missing from the machine code layer underneath all our abstractions. C uses types to make our code a little safer, but it doesn’t stray far from the metal. C++ said that the user should be able to develop new types too, though classes. With so many types lying around, we discussed a need to make our code work with multiple types through the various forms of polymorphism. We looked into C++’s inheritance and template system.
From there we entered the world of functional programming through the lens of Haskell. We spent a lot of time on this language because it had a lot of new ideas. We passed functions around, we used pattern matching to destructure compound structures, we supplied only a subset of a function’s parameters to get back a function awaiting the remainder. We encountered the idea of function literals or lambdas. We saw how the functional patterns of map, filter, and fold underpin a great many of algorithms, and we took those ideas to other languages like Java and Ruby.
Then we visited parameter-passing strategies, and we discovered that not every language is pass-by-copy. The pass-by-closure and pass-by-jit strategies have merit. Their laziness lets us do some crazy things, like write our own looping abstractions.
More recently, we went back to the world of regular expressions as we built a lexer and parser for a language. We got a taste for what an interpreter does to execute our code. We saw that a small language that caters to the application domain can make expressing ideas simpler than a general purpose language. Finally, we got into the world of metaprogramming, in which our programs are aware of themselves. Metaprogramming is an essential feature for a language to have good tools.
We talked about a lot of stuff. Our goal was never for you to have memorized anything or learn the minutiae of ten different programming languages. Rather, my feelings about why this class is important can be summarized in two questions.
Thus we come to the final haiku of the semester:
A legend tells of a test where Muramasa challenged his master, Masamune, to see who could make a finer sword. They both worked tirelessly and eventually, when both swords were finished, they decided to test the results. The contest was for each to suspend the blades in a small creek with the cutting edge facing the current. Muramasa’s sword, the Juuchi Yosamu (“10,000 Cold Nights”) cut everything that passed its way; fish, leaves floating down the river, the very air which blew on it. Highly impressed with his pupil’s work, Masamune lowered his sword, the Yawarakai-Te (“Tender Hands”), into the current and waited patiently. Only leaves were cut. However, the fish swam right up to it, and the air hissed as it gently blew by the blade. After a while, Muramasa began to scoff at his master for his apparent lack of skill in the making of his sword. Smiling to himself, Masamune pulled up his sword, dried it, and sheathed it. All the while, Muramasa was heckling him for his sword’s inability to cut anything. A monk, who had been watching the whole ordeal, walked over and bowed low to the two sword masters. He then began to explain what he had seen.
“The first of the swords was by all accounts a fine sword, however it is a blood thirsty, evil blade, as it does not discriminate as to who or what it will cut. It may just as well be cutting down butterflies as severing heads. The second was by far the finer of the two, as it does not needlessly cut that which is innocent and undeserving.”
Which sword is better?
The unchecked one or the checked?
Well, I’ve got two hands
Here’s your TODO:
There’s no next time!