Overview of Web Programming

Overview of Web Programming - Overview of Web Programming...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Kathi Fisler, WPI October 4, 2004 1 The Problem of Web Programming This lecture looks at programming for web scripts and some of the challenges it raises. Web sites (such as travel sites and onine stores) are often notoriously buggy, even when developed by reputable companies. This suggests that interesting web scripts are somehow complicated to get right. In this lecture, we’re going to try to draw analogies between web programs and the non-web programs that you write to try to understand what’s difficult about writing web scripts. Boxes on forms correspond to requesting inputs (like read in Scheme). Web pages/scripts are like functions: they request a number of inputs from a user and perform some operations on the input, possibly calling other functions (pages/scripts) for additional processing. Pressing buttons on web pages calls functions. Where does this analogy break down? Unlike functions, web scripts terminate as soon as they have passed their form inputs to the next script. The user must press a (submit) button to continue the computation. Furthermore, one script never “returns” a computation to a previous script; in contrast, you rely on one function returning data to another all the time. The implication then is that you have to change how you write programs when you implement web programs. Let’s illustrate this with a simple example. Suppose you wanted to write a program that asks a user to input their age, then displays some information about their ability to vote. Keeping with the idea that we need one page to request input, then another to display the output, we might write a Scheme version of this program as follows: 1 ;; request-age-page : void ;; prompts user to input their age ( define ( request-age-page ) ( begin ( printf " Enter your age: " ) ( read ))) ;; age-page-nonweb : void ;; displays ability to vote based on user’s age ( define ( age-page-nonweb ) ( local (( define age ( request-age-page ))) ( cond [( > = age 18 ) ( printf " Don’t forget to vote! " )] [ else ( printf " You’ll be able to vote in ˜a years " ( - 18 age ))]))) If this were a real web program, the user would get a page with a box in which to enter their age and a submit button. Pressing submit would bring up a new page with the appropriate message from the cond statement. Running it in Scheme would yield the following interaction: 1 we will write our web programs in Scheme because not everyone in the class knows CGI or PHP programming. It’s not hard to translate these programs into equivalent ones in your favorite web programming language. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Overview of Web Programming - Overview of Web Programming...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online