Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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:

1 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 # Related work by Matthias Felleisen, Robby Findler, Kathy Gray, Eli Barzilay, et al

2 July TeachScheme, ReachJava 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

3 July TeachScheme, ReachJava 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

4 July TeachScheme, ReachJava 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

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

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

7 July TeachScheme, ReachJava 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

8 July TeachScheme, ReachJava 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"…

9 July TeachScheme, ReachJava What is CS1 about?

10 July TeachScheme, ReachJava 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

11 July TeachScheme, ReachJava 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)

12 July TeachScheme, ReachJava 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

13 July TeachScheme, ReachJava 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)

14 July TeachScheme, ReachJava 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

15 July TeachScheme, ReachJava 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)

16 July TeachScheme, ReachJava 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!

17 July TeachScheme, ReachJava 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)

18 July TeachScheme, ReachJava 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

19 July TeachScheme, ReachJava Let’s try DrScheme DrScheme Interactions pane (bottom half) Literal expressions – 7 – "hello world" – copy and paste picture from Web browser – true Try

20 July TeachScheme, ReachJava 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

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

22 July TeachScheme, ReachJava 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.

23 July TeachScheme, ReachJava 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))

24 July TeachScheme, ReachJava 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

25 July TeachScheme, ReachJava 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

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

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

28 July TeachScheme, ReachJava 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

29 July TeachScheme, ReachJava 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

30 July TeachScheme, ReachJava 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!

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

32 July TeachScheme, ReachJava 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)))

33 July TeachScheme, ReachJava 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!

34 July TeachScheme, ReachJava 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…

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

36 July TeachScheme, ReachJava 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

37 July TeachScheme, ReachJava 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 "outline" "pink")) (above (beside book (ellipse "outline" "pink")) (beside (ellipse "outline" "pink") book))

38 July TeachScheme, ReachJava 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

39 July TeachScheme, ReachJava 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 "outline" "pink")) (above (beside book (ellipse "outline" "pink")) (beside (ellipse "outline" "pink") book)) (define (counterchange topleft topright) ; topleft an image ; topright an image (above (beside topleft topright) (beside topright topleft)))

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

41 July TeachScheme, ReachJava 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…

42 July TeachScheme, ReachJava 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

43 July TeachScheme, ReachJava 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

44 July TeachScheme, ReachJava 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.

45 July TeachScheme, ReachJava 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


Ads by Google