Past, Present, Future

In a previous post I spoke about the care-and-feeding responsibilities of the first assignment and my experiences with a few different first assignments. Although I left another set of first-assignments go unblogged, a recent event has led me to contemplate a new and different first assignment. A couple of weeks ago I received email from a student indicating she had a question about one of the problems in my now out-of-print C++ text, A Computer Science Tapestry, could she stop by my office to ask about it? “Wow”, I thought, “a Duke student looking at my old book.” She had found the book in the library, by chance choosing my book to help with her work in C++ in a physics lab. She’s a physics major, learning C++ on her own, hadn’t thought of taking a compsci course here [that’s another story].  Her question was about one of the more philosophical end-of-chapter questions, not a “write code for this” question. After answering the question she wanted to show me the program she had done for an earlier chapter, one that gave the user a choice of hair, eyes, nose, mouth, and drew one of several possible faces. She was really proud of her program, had shown it to her advisor, and wanted to show it to me.

It was a revealing moment. She was proud of the creativity she had brought to the program and how she had made it run. This wasn’t exactly using Astrachan’s Law about leveraging the power of the computer, but it has led me to form a corollary [aside: hearing Sally Fincher talk this week at Snowbird using the British pronunciation of corollary was great — her discussion of localites and cosmopolitans as teachers and researchers, respectively, was spot-on and something I’ll follow up later].

The corollary leverages the power of widespread distribution and crowd-sourcing with the creativity of create-a-face or totem-pole examples [draw several faces on top of each other to create a totem pole].  It’s one thing to do this in a program to practice programming, writing functions/methods to decompose the task and to make things work. It’s another to share this with one, two, or a million people. We can easily do this by essentially uploading the face parts, e.g., hair, eyes, nose, mouth, chin, and providing a web-based UI to allow anyone in the world to create a face using student generated parts. I’m hoping we’ll use something like this in our first assignment, getting students to create hair before actually writing Python code, uploading the hair, then putting it in their own program. They could eventually download parts to use, at random or explicitly, in addition to using their own code.  We’d show them how the uploading/extracting server-side code works later and they’d see how they could (easily I hope) write that code part way through the semester.

So, the corollary is

Sharing creativity on a large scale also leverages the power of computing and the network.

I didn’t use any net-centric ideas in formulating my earlier appeal for leveraging computing, it’s time to do that now.  It’s one thing, and it’s a good thing, to write a face-drawing (or space-needle drawing, or graphics drawing) program. It’s another to share this with the universe in an easy way and to talk about how this is done.  As my students know, there’s an unwritten Astrachan’s addiction/dictum that says I need to register domain names to satisfy some secret craving. In support of the ideas I’ve mentioned above look soon to the websites art-i-face.com, arti-face.com, and art-iface.com (all will map to the same site, they’re just placeholders for now). I hope we’ll have these part of both a non-coding day-zero assignment and a day-one programming assignment ready to go soon.

How is this past, present, future? The student who came to my office to show off the program of which she was so proud was the past. That led me to rethink my disdain for drawing programs in light of my present-day satisfaction with the space-needle program mentioned in the earlier-referenced post. The future of this day-zero and day-one assignment is rapidly approaching. I’d like to predict niftyness, but that’s premature. The corollary to Astrachan’s law needs some more backing — any volunteers?

Posted in Uncategorized | 1 Comment

Starting from the beginning

We’ve been wondering what the first Python (programming) assignment should be: what it’s characteristics are, what it tries to get across, the “mood” it engenders in students and the infrastructure in terms of both technology and pedagogy needed to support the first assignment. We think the first assignment is more important than the fourth assignment. We need to set things up “just right”.  To get an idea of what others do, which I hope will inform our process, I decided to do the first assignment from some of the courses I know about or follow. My thoughts below are my thoughts, not those of the group developing this new, first course. My own biases will certainly be deeply ingrained in my explorations and comments.

Stanford 106A First Assignment

(When I started I  recorded/wrote the following:) I’m starting the first Java assignment from the Stanford 106a course http://www.stanford.edu/class/cs106a/ (the first assignment is Karel, I skipped that). It’s 9:05 AM, Monday, May 24 (note: posted roughly three weeks later)

I downloaded a .zip file and imported it into Eclipse where it opened as a Java project named Assignment 2. This download/import worked great, in Eclipse there was a regular Java project with several starter classes, one for each part of the assignment. All the starter classes extended either GraphicsProgram or ConsoleProgram from the ACM (Java Task Force aka jtf) Graphics Library. I had not programmed with this library before.

At 9:15 I had finished reviewing what students know before doing the assignment: loops, the run method from java.acm.GraphicsProgram ( or the Console equivalent), and some examples presumably done in class about using this subclass and writing code. Although students had done Karel programming, none of the Java programs in student handouts before this first assignment had any methods in them other than the run method which is in most ways equivalent to public-static-void-main: it’s the launch point for execution.  I reviewed the acm graphics project about which I knew essentially nothing, though I had read about it a few years ago. My first program drew the right number of rectangles in each row, but the row-indentation was incorrect. This program ran at 9:30. I had fixed the bug by 9:35 (at most), but the output didn’t look right because the graphics window was too small, and when dragged wider didn’t re-center. By changing the BRICK_WIDTH and BRICK_HEIGHT sizes to be smaller I verified that the program was correct. See below for frustration in changing the size of the graphics window. Here’s my final product.

At 9:40 I had skimmed the ACM jtf tutorial and started the rainbow program. I had a very hard time with this due to my glossing over how the GOval class works, missing that the constructor uses a bounding-box, i.e., specifies the upper-left coordinates and a radius.  I couldn’t figure out how to set the size of the window/applet/display, but my program generates an acceptable rainbow. This was a very unsatisfying program. This was my fault, I used a trial-and-error approach rather than a systematic analysis of the API. But the examples left something out from my perspective.  It’s tough debugging where the arc of a rainbow appears.

I skipped the “draw  the inheritance hierarchy” question on my first run-through, I’ll come back to that below. I did the quadratic problem: find roots of a quadratic whose coefficients are entered by the user, took about 5 minutes, no real problems (ha ha, numeric joke).

The range problem took about five minutes: find max and min of a sequence of values entered by user until a sentinel-value is entered. I didn’t know whether to use a while(true) loop or a for(;;) loop [or a sentinel loop, but given the loop-and-a-half problem that Eric Roberts has written about I opted not for that]. I used a for(;;) loop with a break.

It took about 5 minutes for the Hailstone (aka 3N+1) problem as well, nothing of note to write about, I often have to stop myself from writing System.out.print and just writing print, because of my lack of experience with the ACM Java library and graphics package.

I went back to the inheritance hierarchy question because I couldn’t leave the assignment unfinished. Here’s the output of my finished program:

Writing this program was very unsatisfying because I made myself not use a method that would have reduced the clutter/copy-paste aspects of the code. To see what I mean, here’s part of my final program:

rect = new GRect(xc,yc,WIDTH,HEIGHT);
 add(rect);
 label = new GLabel("GLabel",xc,yc);
 label.move((WIDTH-label.getWidth())/2, (HEIGHT-label.getAscent()));
 add(label);
 GLine line = new GLine(lineX,lineY,xc+WIDTH/2,yc);
 add(line);

 xc += WIDTH+GAP;
 rect = new GRect(xc,yc,WIDTH,HEIGHT);
 add(rect);
 line = new GLine(lineX,lineY,xc+WIDTH/2,yc);
 add(line);

 label = new GLabel("GLine",xc,yc);
 label.move((WIDTH-label.getWidth())/2, (HEIGHT-label.getAscent()));
 add(label);

 xc += WIDTH+GAP;
 rect = new GRect(xc,yc,WIDTH,HEIGHT);
 add(rect);
 line = new GLine(lineX,lineY,xc+WIDTH/2,yc);
 add(line);

Clearly it would have been really nice to be able to write and call createFigure(xc,yc,"GLabel") to avoid the repetitive code. Although I was satisfied to have finished, I didn’t really enjoy the experience of writing all these graphics programs. While I understand the need to master the fundamentals of the classes being used, this was all about getting coordinates in the right place and reading an API carefully, not about leveraging abstractions or thinking about how to avoid smelly code or something else. It was with the graphics-hierarchy program that I finally realized I should call setSize and validate to change the size of the graphics display. If that sequence is built into the ACM/Java library I couldn’t find it documented.

U. Washington CSE 142 First Assignment

The UW course is here http://www.cs.washington.edu/education/courses/cse142/10sp/, like Stanford it’s also a Java course. The course espouses a “back to basics” approach which has not been one of my favorite ideas since I first learned about it. Start with static methods, repeat the ideas from one of my all-time favorite texts, Stuart Reges’ Building Pascal Programs. I’ve chided Stuart for really leveraging the power of computing in the 21st century (not!) by writing programs to build ASCII rocketships. Here’s the output of my version of the first UW programming assignment that uses loops. The very first assignment is to print a song with repetitive verses, I skipped that.

               ||
               ||
               ||
               ||
               ||
            __/||\__
         __/:::||:::\__
      __/::::::||::::::\__
   __/:::::::::||:::::::::\__
__/::::::::::::||::::::::::::\__
|""""""""""""""""""""""""""""""|
\_\/\/\/\/\/\/\/\/\/\/\/\/\/\/_/
  \_\/\/\/\/\/\/\/\/\/\/\/\/_/
    \_\/\/\/\/\/\/\/\/\/\/_/
      \_\/\/\/\/\/\/\/\/_/
        \_\/\/\/\/\/\/_/
               ||
               ||
               ||
               ||
               ||
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            |%%||%%|
            __/||\__
         __/:::||:::\__
      __/::::::||::::::\__
   __/:::::::::||:::::::::\__
__/::::::::::::||::::::::::::\__
|""""""""""""""""""""""""""""""|

I liked this assignment! This was a surprise since I had been against ASCII art in theory. What I liked about it was that the assignment specified that “source code aesthetics” would be part of the grading, including using methods to eliminate redundancy. Students were told they could use a method with parameters “If you like”, because that concept was from what must be the next chapter to be covered when the assignment is given out. If I gave this assignment I think I’d provide this method which sure makes the coding simpler, why make the assignment easier only for students who see the abstraction?

public static void repeat(int n, String s){
  for(int k=0; k < n; k++){
    System.out.print(s);
  }
 }

As I was writing this code it was more straightforward to fix simple mistakes than it was to do so with the graphics programs from the Stanford 106A assignment. For example I had a small bug in parameterizing the size of the  space needle that didn’t manifest itself when drawing the “normal” size, but did when making the needle bigger (change one constant to make the needle larger was part of the assignment specification). It was easy to fix since I had  written roughly seven methods and the buggy method was easy to find since the part of the program that generated the not-indented-properly middle was simple to spot and fix. This might have been harder to find in repetitive, straight-line, copy/pasted code.

Harvard CS50

The Harvard CS50 course is full of interesting stuff — the web-based materials are without rival in terms of completeness and slickness — where slick-is-good. You can see last year’s materials at http://cs50.tv even the URL is slick! The first assignment uses Scratch, I skipped that and went for the first non-Scratch, that is to say C assignment. I’ll save a different post for a diatribe on using C as the primary language in a first course. There are clearly local@harvard reasons for doing so and the course is incredibly successful at Harvard, but I wouldn’t think about adopting the language. But if I wanted to I could use their appliance and not even worry about operating systems, compilers, and so on. That’s very slick as well as being cool, kudos to David Malan and his group for the entire endeavor (despite my doubts about the use of C). The first assignment is to write three programs, plus compile and run your own version of hello world. The three programs are (1) prompt for a number representing an ISBN and verify that it’s valid (check sum); (2) write a program that determines the minimum number of coins to give for change using the greedy-ready American system of coins; and (3) print an asterisk half-pyramid. These assignments are clearly designed to practice with input, mod/div, and loops. they were mildly interesting, though the asterisk-pyramid was less interesting than the other assignments. In testing the ISBN program I thought it would be nice to have a framework that effectively ran the program for each line of an input file to be able to test a bunch of ISBNs without entering each one-at-a-time. I did a similar program in the cs50 Hacker version (read: more programming/algorithm knowledge required) to check credit-card numbers as valid. That was pretty similar to the ISBN-check. At first I tried to do the programs without the cs50 library, which basically provides a string type and easy IO avoiding scanf. Trying to figure out that scanf(“%lld”,&num) was needed to read a long long type was non-trivial (it’s the% lld that I didn’t know off the top of my head). So I ended up using the cs50.h/.c library and realized again why I’d choose not to use C — just to avoid the compile, link, run headaches of missing the -std=c99 flag that I needed in my environment. As an example, here’s my isbn.c with the debugging statement commented out

#include "cs50.h" 
#include <stdio.h>
int main(){ 
    long long num; 
    num = GetLongLong(); 
    int total = 0; 
    for(int k = 10; k >= 1; k--){ 
        total += k*(num%10); 
        num /= 10; 
    } 
    //printf("tot=%d, num=%lld\n",total,num); 
 
    if (total % 11 == 0){ 
        printf("YES\n"); 
    }  
    else { 
        printf("NO\n"); 
    }
}

Summary

I’ll know what our first assignment is in a couple of weeks. I’ll be posting soon about Harvey Mudd’s Python-based first course soon as well. In making progress toward a first assignment I have a few take-aways from the three course/examples above. I want to avoid the nit-picky get-the-coordinates and parameters right problems I had with the Stanford assignment. I realize the need for coping with and mastering this kind of problem, but I don’t want that to be the first program. I’d like to part of the first program involve something that computers are useful for. Arguably checking an ISBN or a credit card number doesn’t require lots of computing-power, but it happens all the time.  I think providing a driver for getting data, e.g., a string or a list, into a method that students write is probably a good idea. The satisfaction I got from getting the space needle done is something I’d like to get across and get from the students, I’m not sure how that will turn out. Both Standofr and Harvard require non-standard libraries. I’d like to stay away from “easy-IO” libraries. I’m willing to use numpy/scipy/PIL and other libraries in Python, but we’ll ahve to make that seamless in our programming environment.

In the end, I want to convey both the joy of writing programs and the utility and power of computing. We’ll see how that gets done.

Posted in Uncategorized | Leave a comment

Hello world!

We are designing a new first course, changing the approach we use and the language we use, but trying to avoid re-inventing everything. Making information available to everyone might help as we try to design the course with input from our local gang-of-four educators: those who will ultimately teach the course. But the design efforts are being coordinated by the two folks teaching the course in the fall (of 2010).

Why are we designing a new course?

  • We have two CS2 courses: one for engineering students, specifically electrical and computer engineering students, and one for everyone else. The first group knows Matlab, the second group knows Java from our first course or the equivalent. There is substantial overlap in these courses, and teaching two such similar courses is using too many of our course-teaching-load-hours. We’d like to teach one CS2 course. Constraint: change the language so that it’s not-Java so students come into our CS2 course with similar,non-Java previous programming experience.
  • Our first course has been taught in Java since 2004 when we switched from C++. At the same time we switched languages we  instituted a prerequisite: students taking the first course should have some previous programming experience: loops, functions, and arrays. We made the changes for sound-at-the-time reasons, but the previous programming experience requirement is now an impediment that we’d like to remove, students are less inclined to take a first course that has a prerequisite. Constraint: remove the previous experience necessary prerequisite and make the course accessible to more students (that’s two constraints in one).
  • Over the past six years we’ve emphasized object-oriented programming (or objects-first, or object-based or something similar) and used examples and assignments grounded in computer science. We’d like to move away from object-oriented to some degree and widen the domain/universe of problems we use in our examples. Constraint: use interdisciplinary examples as well as those drawn from computer science, leverage the power of computing.

Our new first course, to be delivered in the fall of 2010, will use Python as the language. We’ll develop a sequence and collection of interdisciplinary examples that illustrate the power of computing as well as the profound awe and sense of accomplishment we hope to instill in students by getting them to master rudimentary programming.

Posted in Uncategorized | 2 Comments