« Hotlinking solved | Main | Export photography »

Making things deliberately difficult

This morning, after I spent an hour and a half or so sitting on stools in the stacks of the library with Professor Σ looking at textbooks (we seem to have finally found one) I took on the task of writing the first homework assignment.

We assume that the students know some C++, but probably not much else as far as programming goes. (That’s going to change in a hurry.) Professor Σ’s stated (if ambitious) goal for this course is to give the students a feeling for why one would choose one language over another in a given situation, and what makes particular languages good for particular tasks. So this assignment was to ask a language to do something it’s bad at—in this case, to ask C++ to parse a text file.

The assignment I came up with asks the students to write a C++ program which parses /etc/passwd, ignoring comment lines, and print the first, sixth, and seventh columns. (Columns in /etc/passwd are separated by “:” characters.) Then I tried doing it myself. I’m not an ace C++ hacker, but I was able to do it with Perl in eight lines… and in C++ I took 37 lines.

I suppose an optional way to make it tougher would be to require that only entries with valid shells be printed out. Perl, again, could handle that with maybe three or four more lines; I can’t even imagine how I’d do it with C++ (though, again, I’m sure it’s possible.)

It looks like I’ll be learning some Scheme. And I’m tinkering with Ruby anyway…

Now Playing: Too Fast For You from Hindsight by The Church

Technorati Tags: , , , ,

Comments

I remember vividly one assignment that I did for Programming Languages. I wrote a 6502 assembler in SNOBOL. Now that was fun!

Post a comment