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.

Advertisements

About astrachano

Teacher, educator, programmer, designer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s