# TeachScheme, ReachJava Stephen Bloch, Adelphi University, Garden City, NY John Clements, Cal Poly, San Luis Obispo, CA Kathi Fisler, Worcester Polytechnic.

## Presentation on theme: "TeachScheme, ReachJava Stephen Bloch, Adelphi University, Garden City, NY John Clements, Cal Poly, San Luis Obispo, CA Kathi Fisler, Worcester Polytechnic."— Presentation transcript:

TeachScheme, ReachJava Stephen Bloch, Adelphi University, Garden City, NY John Clements, Cal Poly, San Luis Obispo, CA Kathi Fisler, Worcester Polytechnic Institute, Worcester, MA Matthew Flatt, University of Utah, Salt Lake City, UT Shriram Krishnamurthi, Brown University, Providence, RI Viera K. Proulx, Northeastern University, Boston, MA Supported by NSF grant #0618543 Related work by Matthias Felleisen, Robby Findler, Kathy Gray, Eli Barzilay, et al

July 10 2010TeachScheme, ReachJava 20102 What is a problem? What is the meaning of life? – Not an objective question How old am I? – An objective question, which requires information you don’t have What is the smallest prime number? – An objective, fully-specified question, but once it’s answered once, it’s over

July 10 2010TeachScheme, ReachJava 20103 What is a problem? What is the Celsius equivalent of 45F? – Again, once it’s answered, it’s over What is the Celsius equivalent of 87F? – Ditto, but closely related What is the Celsius equivalent of ___ in Fahrenheit? – Generalizes infinitely many questions

July 10 2010TeachScheme, ReachJava 20104 What is a problem? Question: has a single answer Problem: large (or infinite) family of questions, sharing some features & differing in others Program: general rule for solving a problem, with input for the features that differ Computation: a program working on particular input to produce particular results

July 10 2010TeachScheme, ReachJava 20105 Introductions Who are you? What kind of school? students? Background in teaching CS Background in Scheme, Java, etc?

July 10 2010TeachScheme, ReachJava 20106 This week You’re primarily students, not teachers Get “the student experience” of this approach — only faster Occasional breaks to talk pedagogy

July 10 2010TeachScheme, ReachJava 20107 What is “computer science”? “microscope science” — about microbes “telescope science” — about stars It’s not about the tool, it’s about what you can study using the tool! “computer science” — about information and the manipulation thereof

July 10 2010TeachScheme, ReachJava 20108 What is a beginning CS course about? 1)How to use Microsoft Office et al 2)Survey of the CS profession 3)A language that will get students jobs 4)Concepts, habits, & methodologies of programming Four completely different courses, each valuable for different reasons and audiences #3 useful for students about to graduate, or about to get internships and summer jobs #4 more useful as a first course. Let's call it "CS1"…

July 10 2010TeachScheme, ReachJava 20109 What is CS1 about?

July 10 2010TeachScheme, ReachJava 201010 What you teach blah algorithm blah variable blah function blah data type blah object blah re-use blah methodology blah testing blah design blah composition blah refinement blah abstraction

July 10 2010TeachScheme, ReachJava 201011 What they hear blah ; blah { blah ) blah ] blah return blah this.x = x; blah public static void main (String[] args) blah /* blah // blah blah if ( blah JOptionPane blah class Posn(int x,y)

July 10 2010TeachScheme, ReachJava 201012 Programming languages: a necessary evil Necessary: to write real programs that really run on real computers Evil: distract students from the important stuff Will be obsolete in a few years anyway

July 10 2010TeachScheme, ReachJava 201013 How to minimize language & IDE? Introduce features one at a time Avoid "black magic"; never ask students to write anything they can't understand now Introduce features only as necessary to teach an important concept Corollary: any feature that doesn't help teach a CS1 concept shouldn't be mentioned in CS1 Corollary: need enforced language subsets so students don't accidentally use language features they haven't seen For GUI, robotics, networking, etc. need interface between student code (in subset) and library code (in full language)

July 10 2010TeachScheme, ReachJava 201014 What Java do we need? When? Realistically, most of us must cover a certain amount of Java by the end of CS2 Not obvious that the best way to do this is Java from start of CS1 Instead, teach concepts & habits first, then complicated language

July 10 2010TeachScheme, ReachJava 201015 Alternatives to Java-first Leading alternatives: Alice, Python, Scheme All three: start w/simpler syntax while students master concepts Difference: Alice & Python usually taught imperatively; Scheme usually functionally (Functional-first Python: has potential)

July 10 2010TeachScheme, ReachJava 201016 Why functional? Simple, familiar semantic model – 3+4*5 => 3+20 => 23 Ease of writing test suites – each test is usually one stmt, rather than "set up", "call method", "check side effects" – tests order-independent – no worry about aliasing, equals() vs. ==, etc. – If testing is easy, students may actually do it!

July 10 2010TeachScheme, ReachJava 201017 But what about OOP? Students need to learn OOP, and an OO language, by 2nd or 3rd semester OOP is a terrific way to organize multi-KLOC programs First-term students don't write multi-KLOC programs OOP's benefits aren't apparent in first term; students see only the overhead (Challenge: write a short, OO C++/Java program that wouldn't be simpler without OO)

July 10 2010TeachScheme, ReachJava 201018 Main points of TSRJ Multi-language approach to CS1/CS2 – Start in Scheme, develop concepts & habits – Switch to Java after 2-4 months Step-by-step design recipe in both languages – concrete questions & products at each step – test-first methodology – strong emphasis on data types – shape of data determines shape of code & test cases DrScheme development environment – beginner-friendly – interactive testing and experimentation – enforces language subsets w/appropriate messages

July 10 2010TeachScheme, ReachJava 201019 Let’s try DrScheme DrScheme Interactions pane (bottom half) Literal expressions – 7 – "hello world" – copy and paste picture from Web browser – true Try www.picturingprograms.com/pictures/

July 10 2010TeachScheme, ReachJava 201020 Operating on pictures (reflect-vert paste-picture-from-Web) Same with reflect-horiz, rotate-cw, rotate-ccw, rotate-180 (above picture1 picture2) Same with beside, overlay – These three actually accept two or more pictures. Syntax rule: ( operation pic1 … ) Terminology: expression, function, argument, value, literal

July 10 2010TeachScheme, ReachJava 201021 Composing functions > (beside (reflect-horiz )) Exercise: write expressions to produce

July 10 2010TeachScheme, ReachJava 201022 Scheme syntax All expressions fully parenthesized; no order of operations to memorize All functions (both built-in and user-defined) are prefix, inside parentheses Some functions have arity 1, some 2, some "2 or more", etc. as appropriate.

July 10 2010TeachScheme, ReachJava 201023 Definitions pane Editable and savable "Run" button evaluates all expressions in order, replacing old Interactions Try 7 "hello world" copied image from Web (above (rotate-cw picture) (rotate-ccw picture))

July 10 2010TeachScheme, ReachJava 201024 The Stepper Type several nested expressions into Definitions pane Click "Step" button at top See each sub-expression replaced with its value, one by one Valuable for students who never really "got" algebra

July 10 2010TeachScheme, ReachJava 201025 Variable definitions (define calendar ) (above calendar (reflect-vert calendar)) Define another variable to hold a different picture copied from the Web; write some expressions using both. Note no declared data type; data have types, variables don't

July 10 2010TeachScheme, ReachJava 201026 Building images from scratch (rectangle 34 21 "solid" "blue") (circle 18 "outline" "green") (ellipse 34 55 "outline" "purple") (triangle 22 "solid" "pink") (star 7 20 10 "solid" "blue") (text "Hello there" 18 "blue") Try your own variations (define blue-star (star 7 20 10 "solid" "blue")) Try modifying & combining these using above, overlay, reflect-vert, rotate-cw, etc.

July 10 2010TeachScheme, ReachJava 201027 Terminology Three kinds of literals: image (pasted from Web browser), number, and string. Data types

July 10 2010TeachScheme, ReachJava 201028 Function contracts ; reflect-vert : image -> image ; reflect-horiz, rotate-cw, rotate-ccw, rotate-180 : similar ; beside : image image … -> image ; above, overlay : similar ; rectangle : number(width) number(height) string(solid/outline) string(color) -> image Summarizes what a function takes in and returns, in a brief, standard notation Note semicolon for comment-to-end-of-line

July 10 2010TeachScheme, ReachJava 201029 More image functions ; crop-bottom : image number(pixels) -> image ; crop-top, crop-left, crop-right : similar ; image-width : image -> number ; image-height : similar ; place-image : image(foreground) number(x) number(y) image(background) -> image ; text : string(text) number(size) string(color) -> image

July 10 2010TeachScheme, ReachJava 201030 Defining functions > (define (mirror picture) (beside picture (reflect-horiz picture))) (mirror calendar) (mirror (rotate-cw (triangle 10 "solid" "blue"))) Note no declared parameter or return types; again, data have types Try (mirror calendar hacker) -- wrong number of arguments! Try (mirror 7) -- wrong type of argument!

July 10 2010TeachScheme, ReachJava 201031 Exercise Define a function four-square that takes in an image and produces a 2x2 arrangement of it like

July 10 2010TeachScheme, ReachJava 201032 Worked Exercise Define a function counterchange that takes in two images and produces a 2x2 arrangement like My answer: (define (counterchange topleft topright) (above (beside topleft topright) (beside topright topleft)))

July 10 2010TeachScheme, ReachJava 201033 Testing functions With English descriptions: – (mirror calendar) "should be a calendar on the left, and a right-left-reflected calendar on the right" With check-expect: – (check-expect (mirror calendar) (beside calendar (reflect-horiz calendar))) Put either or both in Definitions window; hit Run & see what happens. Try with wrong function definition!

July 10 2010TeachScheme, ReachJava 201034 Design recipes We could write counterchange in an ad-hoc way, but in general we use… Step-by-step recipes to get from English-language description to working, tested code One recipe for functions, one for data types, one for abstractions, one for event-driven animations…

July 10 2010TeachScheme, ReachJava 201035 How to accomplish anything 1)Figure out what you want to do 2)Do it 3)Check that you did it right

July 10 2010TeachScheme, ReachJava 201036 How to write a function/method Figure out what you want to do Contract: Specify name, inputs, outputs Data definition: Identify any new data types in the problem Examples: Write test cases with expected answers Do it Skeleton: Write boilerplate code for function definition Inventory: Write available expressions, their types, and (later) their values for a non-trivial test case Body: Fill in details based on problem to solve Check that you did it right Testing: Run test cases

July 10 2010TeachScheme, ReachJava 201037 The design recipe in practice contract: ; counterchange : image (topleft) image(topright) -> image data definition: problem only involves images, which are predefined test cases: (check-expect (counterchange calendar schemelogo) (above (beside calendar schemelogo) (beside schemelogo calendar))) (check-expect (counterchange book (ellipse 30 10 "outline" "pink")) (above (beside book (ellipse 30 10 "outline" "pink")) (beside (ellipse 30 10 "outline" "pink") book))

July 10 2010TeachScheme, ReachJava 201038 The design recipe in practice skeleton: (inserted before examples) (define (counterchange topleft topright) ) inventory: (define (counterchange topleft topright) ; topleft an image ; topright an image ) body: (fill in something real, using expressions from inventory) (define (counterchange topleft topright) ; topleft an image ; topright an image (above (beside topleft topright) (beside topright topleft))) testing: hit "Run" and see whether tests pass

July 10 2010TeachScheme, ReachJava 201039 The result ; counterchange : image (topleft) image(topright) -> image (check-expect (counterchange calendar schemelogo) (above (beside calendar schemelogo) (beside schemelogo calendar))) (check-expect (counterchange book (ellipse 30 10 "outline" "pink")) (above (beside book (ellipse 30 10 "outline" "pink")) (beside (ellipse 30 10 "outline" "pink") book)) (define (counterchange topleft topright) ; topleft an image ; topright an image (above (beside topleft topright) (beside topright topleft)))

July 10 2010TeachScheme, ReachJava 201040 Testing again Change the definition so that it's wrong; run the tests again and see what happens.

July 10 2010TeachScheme, ReachJava 201041 Design recipes as pedagogy Note "test-first" methodology (a la XP); identify special cases before writing code Use as grading rubric: partial credit for each step First steps are in comments; non-threatening, avoids "blank page syndrome" Each step has concrete questions and concrete products I don't help with step N until I see step N-1 Same steps apply in Java, C++, etc. (but more complicated) Know-it-all students usually try to skip the recipe… until Chapter 12 of HtDP, or Chapter 23 of PP…

July 10 2010TeachScheme, ReachJava 201042 Exercises Write contracts and test cases, but no definitions, for 1)a function named copies-beside that takes in a number and an image, and produces that many copies of the image side by side 2)a function named pinwheel that takes in an image & produces a 2x2 rotated thing like 3)a function named checkerboard2 that takes in two color names & produces a 2x2 checkerboard in those colors

July 10 2010TeachScheme, ReachJava 201043 Exercises Write skeletons & definitions for pinwheel and checkerboard2 (you don't know how to do copies- beside yet) Do all the steps to define lollipop, which takes in two numbers and a color name, and creates a picture of a lollipop w/specified radius, stick length, and color

July 10 2010TeachScheme, ReachJava 201044 Exercises Do all the steps to define diamond, which takes in a color name and a number, and creates a picture of a diamond w/specified color and side length.

July 10 2010TeachScheme, ReachJava 201045 Discussion break How is this different from what you've done in the past? How much explaining would it take for your students? I have a lot of mathophobic students, so I start with images rather than numbers and algebra. The prefix notation doesn't throw them, because they don't already "know" the "right" notation for operating on images.

Download ppt "TeachScheme, ReachJava Stephen Bloch, Adelphi University, Garden City, NY John Clements, Cal Poly, San Luis Obispo, CA Kathi Fisler, Worcester Polytechnic."

Similar presentations