The first lecture argued that programming and programming languages are deeply intertwined; programming languages affect how we think about programming, and new programming problems inspire evolution in programming languages. This project explores the relationship between batch (standard textual, sequential) and web programming to set the stage for the programming languages topics that we will cover after the midterm.
We will do the project in two stages. This handout describes the first stage; the second stage handout will be provided after the midterm.
After completing this stage of the assignment, you should be able to:
The project is due February 3 (Sunday) at 11:59pm via turnin (use assignment name project1).
Note that the due date is right after the midterm. We will begin discussing web programming in class just after the midterm, and you need to have done this project before we discuss web programming in class. Rather than force everyone to turn the project in earlier, I've set the due date to give you flexibility in scheduling your time. However, the due date is a rope don't hang yourself with it. I will not grant extensions on this project unless you have a documented emergency.
If you've never written web pages or scripts, the programming parts of the assignment may be a bit time-consuming. Start early.
If you need help figuring out what the assignment is asking you to do or how to get started, come to office hours for help.
This stage has three parts: two programming parts, and one analytical part. Be sure to keep a copy of all work you do on this stage for use in the next stage.
You're going to implement a simplified prototype of a program for generating driving directions (similar to the programs on the web that do this -- see Yahoo!'s driving direction service for an example). A request for directions contains several pieces of information: the origin and destination cities, whether to display all routes found or just the shortest route, the name of a city to avoid (if any), and the name of a city to visit enroute (if any).
The actual driving direction services on the web let you store your home address so that you don't need to type it in every time. In similar spirit, users of your program should only need to enter their starting city once (this will be called the "personalization feature" in the rest of this document).
In this assignment, you will implement two versions of the simple driving directions program: one textual (in Scheme) and one web-based (in the CGI scripting language of your choice). Each prototype will gather information about the desired route and display possible routes that satisfy the constraints. Your prototypes must support at least the set of cities and routes provided below. See the interface prototype samples for an idea of what kind of interfaces we expect you to develop for this assignment. You may develop fancier interfaces if you choose, but be aware that they will not earn you extra points towards your project grade.
Your prototype should support at least the following routes/distances, in either direction. Your program can hard-code the listed routes -- you do not need to write a program to generate the routes from the distances between individual cities.
| Route | Distance |
|---|---|
| Providence-Hartford | 75 |
| New Haven-Hartford | 39 |
| New Haven-New York | 80 |
| Hartford-New York | 120 |
| Worcester-Hartford | 63 |
| Worcester-Providence | 40 |
| Worcester-Boston | 47 |
| Providence-Boston | 50 |
| Providence-Hartford | 75 |
| Providence-New Haven | 103 |
| Providence-Hartford-New Haven | 134 |
| Boston-Providence-New Haven-New York | 233 |
| Boston-Worcester-Hartford-New York | 230 |
| Boston-Providence-Hartford-New York | 245 |
| Boston-Worcester-Providence-New Haven-New York | 270 |
In both programming problems, assume that the user of your programs always enters valid input. You programs do not need to do any error checking.
Write the textual prototype in Scheme. The Scheme version does not need to implement the personalization feature. Develop (and use) the following programs as part of your solution:
prompt-read-many : list[string] -> list[symbol]
consumes a list of prompts, presents each prompt in turn and gathers
the data collected into the output list. The answers in the output
list should occur in the same order as their prompts are in the input
list.
Note that this contract implies that we will view city names as symbols rather than strings. This means that city names must be a single sequence of characters (e.g. 'new-york, not "New York"), but this will simplify parts of the project down the road.
display-routes : symbol list[symbol] -> void
consumes the data that has been entered and displays a summary of
available routes. The first input symbol is the origin city; the
second input list contains all of the remaining information
(destination, which routes, city to avoid, and city to visit).
Write the web prototype as a series of forms and scripts using the CGI protocol. You may implement your scripts in any language (Perl, Python, Scheme, etc). The web prototype should support the personalization feature, but without adding more than 8 characters to the ordering pages' URLs (i.e. don't embed the personalization data directly in the URL). Ideally, the feature should not require the customer to enter some sort of id or username (such a solution will earn only half-credit on this part of the assignment).
Use two pages for collecting data as shown in the interface sample.
The Links and Hints section further down on this page has pointers to material on CGI scripting.
Based on your two prototypes, answer the following questions:
What language did you use for the web-based program?
What is the URL for trying your web prototype? (for use in grading make sure that your script will run from anywhere on CCC)
Modify both prototypes to contain each of the following errors. In each case, how did you discover that an error occurred and what information did you get to help you locate the source of the error?
How does each prototype communicate the origin city to the part of the program that computes the routes to display?
For each function in your Scheme implementation (including prompt-read-many and display-routes), indicate the corresponding construct that implements that function in the web prototype.
Provide instructions for a customer to reuse their origin city across multiple direction searches at multiple times (the graders will use your instructions while grading, so make sure they are clear).
Describe your solution (in technical terms, not for a "customer") and justify why it correctly implements the personalization feature.
If you are unable to get this feature working, describe the technical problem(s) that you would have to solve in order to provide this feature. Paraphrasing the assigned problem is insufficient. Your answer should describe precise programming problem(s): for example, "I need to convert a foo into a quux and perform operation baz on quux".
Write a brief (2-3 paragraph) summary of your observations during this project. What do you see as the differences, strengths, and weaknesses of programming in each context (textual and web)? Which context gave you more assistance as a programmer? What challenges exist to programming in each context that doesn't exist in the other?
Your answer should contrast the programming experience in these two contexts. You may discuss features of the languages used for each part, but keep your comments technical (i.e.: statements like "I don't like language X" will cost you points, while comments like "the Y feature of language X made it difficult to generate the data for Z" are fine).
the textual Scheme prototype under filename routes.ss or routes.scm. The top of this file should contain a comment telling us how to run your program.
copies of all html files and scripts that you wrote for the web prototype. No specific naming convention is required. Also leave the scripts in place in your account so we can test them (starting from the URL supplied in the report).
a single text file (under filename report.txt) containing your answers to the questions about your two prototypes.
Your prototypes will be graded on whether they collect and process the necessary information properly. They will not be graded on their visual appearance. In contrast, adding features while your program isn't yet robust will cost you points.
We will grade your report for writing (complete sentences, spelling, punctuation, clarity, etc) as well as technical content.
We will look for whether you followed good coding practices, such as uses of helper functions, in your prototypes. Remember that there will be a second part to this assignment; you don't know what we will ask you to change for the second part, so try to structure your code so as to localize potential changes.
We expect you to follow the Laws of Homework on this assignment, with the exception that you may use the I/O primitives and begin.
NOTE: I do not intend for you to go buy books on CGI programming, or to spend hours pouring through html documentation to figure out individual language constructs. If you know precisely what you want to do, but aren't sure how to do it, ask one of the course staff!. I want you to spend your time figuring out the kinds of constructs that you need, not the minute details of writing them down. Please don't post these kinds of questions to the discussion board though -- we want everyone to figure out the big picture without hints from the discussion board.
Suggestions for links to additional tutorials and pages that you find useful in doing this assignment are welcome.
CCC's page on using CGI at WPI will help you get started writing CGI scripts. It also explains WPI's policies on running your scripts.
If you search for "cgi" in the DrScheme help-desk, you'll get a tutorial on writing CGI scripts in MzScheme.
If you use Perl, the sysadmins suggest that you put the following line in your script, right after the #!/usr/local/bin/perl line:
use CGI::Carp 'fatalsToBrowser';
A CGI-tutorial from python.org and another intro to writing CGI scripts in Python
For I/O in Scheme, you will most want the commands (all documented in the help-desk):
Example:
(define (age-to-year)
(begin
(printf "Enter your age: ")
(let ([age (read)])
(printf "You were born in ~a or ~a~n"
(- 2001 (+ 1 age)) (- 2001 age)))))
This is an individual project. Collaboration is not permitted on this assignment. The course staff are the only people you may approach for help with this project. You may not ask anyone outside of the course staff questions on any aspect of this project, including how to write and run CGI scripts; this includes webmaster@wpi or helpdesk@wpi. If you believe there's a problem with running CGI scripts from your account that warrants CCC assistance, get permission from the course staff to contact helpdesk.
In particular, do NOT bother webmaster@wpi or helpdesk@wpi if you get an "Internal Server Error" while developing your code. This error likely appears due to a bug in your script, not a problem on the server. If you are convinced you have a server error, contact the course staff before contacting any systems staff.