Monday, September 12, 2011

Teenagers, programming, constants

Teaching a functional programming language to first year students, I tell them: "We can define constants by writing statements such as: (define myconstant 3.14). In the rest of the program, whenever the term "myconstant" is encountered, the quantity 3.14 will be substituted for it."

I explain the rules. Questions come. Then, suddenly there was an avalanche of questions offering crazier and crazier possibilities: -"What if you write (define 3 4)?"
-"How about (define + 8)?"
-"What about (define define 2)?" (I had to make the student repeat that question before I understood it).
-"How about (define define define)?"

I had never thought of doing any of those things. Very creative! They're teenagers: they like to see how far they can push the rules before being hit back with an error message. Suddenly a boring lecture turned into an exciting challenge: just what crazy bits of code does the language let you get away with? That does not encourage good programming habits, but it's an exploration of what constant definition really means, and it may help understand it in more depth. Maybe some other year there should be an exercise around that!

3 comments:

  1. Makes one wonder how they would push the limits if we told them they could hide constants in the O-notation. :-)

    ReplyDelete
  2. Great question. It just goes to show how uncomfortable most students are with Math, that I have never had questions of that type when teaching big-ohs. Great idea. I will try to make that happen next semester!

    ReplyDelete
  3. In fact the questions are very good because they will get the idea that one can treat programs as text and this is very useful in theory of computation and parsing etc.

    ReplyDelete

Note: Only a member of this blog may post a comment.