teaching machines

CS 330 Lecture 39 – Exit

Dear students,

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:

  • Recognize and exploit the strengths of three major programming paradigms: imperative, functional, and object-oriented.
  • Reason about the strengths and weaknesses of various type systems.
  • Weigh the costs and benefits of static and dynamic decision making.
  • Develop code in languages with addressable and dynamically-allocated memory.
  • Design and develop tools for recognizing and interpreting domain-specific languages.

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.

  1. Is a spider’s web a tool? When I think of tools, I think of something external to the tool user. But a spider’s web comes from its abdomen. It is something internal made external. In this sense, it is much more than a tool. I feel the same way about language in general. Our brains have this uncanny facility for recognizing and generating language. Grammars and encodings seem to naturally flow out of the cerebral cortex to help us communicate. A programming language is not some external force acting upon us. It comes from us, it is us, and it shapes what we can do. It is my hope that the tools that you encounter in your lives embed themselves inside you and give the ideas that are inside of you a voice. If the right tool doesn’t exist, you have what it takes to make your own. I hope you can teach those ideas to a machine, and share them with others. If you can make some money off of them, all the better.
  2. In which of Perry’s stages of cognitive development are you? The early stages have us believing that the world is full of accurately labeled things, each marked good or bad. The middle stages have us believing that those labels were placed at random, and we reject the very idea of good and bad. We don’t realize our own hypocrisy in that we are labeling labels as bad. The final stages have us accepting that our world is full of mixed bags, that some things are better than others, and that both good and bad things can be made better. This situation is extremely relevant to our discipline, in which people are eager to sell their soul to a particular technology. It’s kind of like sports. You invest your identity in something in which you have no participation. Your future workplaces may be very happy to let you become an expert at one particular good thing, but you will calcify and obsolesce with that technology. Let me tell you the story of two swordsmiths of Japan—courtesy of Wikipedia:

    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.”

    Thus we come to the final haiku of the semester:
    Which sword is better?
    The unchecked one or the checked?
    Well, I’ve got two hands

Here’s your TODO:

  • Complete your takehome final exam. I ask that you test all code that you write. Haphazard answers that do not appear to be tested will not receive credit. Slide your exam under my office door before noon on Friday, May 19. Electronic submissions are not accepted.

There’s no next time!

Sincerely,

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *