TeachScheme, ReachJava - PowerPoint PPT Presentation

About This Presentation
Title:

TeachScheme, ReachJava

Description:

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

Number of Views:48
Avg rating:3.0/5.0
Slides: 46
Provided by: Stephe703
Learn more at: https://home.adelphi.edu
Category:

less

Transcript and Presenter's Notes

Title: TeachScheme, ReachJava


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

2
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 dont have
  • What is the smallest prime number?
  • An objective, fully-specified question, but once
    its answered once, its over

3
What is a problem?
  • What is the Celsius equivalent of 45F?
  • Again, once its answered, its 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
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
Introductions
  • Who are you?
  • What kind of school? students?
  • Background in teaching CS
  • Background in Scheme, Java, etc?

6
This week
  • Youre primarily students, not teachers
  • Get the student experience of this approach
    only faster
  • Occasional breaks to talk pedagogy

7
What is computer science?
  • microscope science about microbes
  • telescope science about stars
  • Its not about the tool, its about what you can
    study using the tool!
  • computer science about information and the
    manipulation thereof

8
What is a beginning CS course about?
  • How to use Microsoft Office et al
  • Survey of the CS profession
  • A language that will get students jobs
  • 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
What is CS1 about?

10
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
What they hear
  • blah blah blah ) blah blah return blah
    this.x x blah public static void main
    (String args) blah / blah // blah ltintgt blah
    if ( blah JOptionPane blah class Posn(int x,y)

12
Programming languagesa 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
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
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
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
Why functional?
  • Simple, familiar semantic model
  • 345 gt 320 gt 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
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
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
Lets 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/

20
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
Composing functions
  • gt (beside (reflect-horiz ))
  • Exercise write expressions to produce

22
Scheme syntax
  • All expressions fully parenthesizedno 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
Definitions pane
  • Editable and savable
  • "Run" button evaluates all expressions in order,
    replacing old Interactions
  • Try7"hello world"copied image from Web(above
    (rotate-cw picture) (rotate-ccw picture))

24
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
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 typedata have types,
    variables don't

26
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.

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

28
Function contracts
  • reflect-vert image -gt image
  • reflect-horiz, rotate-cw, rotate-ccw,
    rotate-180 similar
  • beside image image -gt image
  • above, overlay similar
  • rectangle number(width) number(height)
    string(solid/outline) string(color) -gt image
  • Summarizes what a function takes in and returns,
    in a brief, standard notation
  • Note semicolon for comment-to-end-of-line

29
More image functions
  • crop-bottom image number(pixels) -gt image
  • crop-top, crop-left, crop-right similar
  • image-width image -gt number
  • image-height similar
  • place-image image(foreground) number(x)
    number(y) image(background) -gt image
  • text string(text) number(size) string(color)
    -gt image

30
Defining functions
  • gt (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
Exercise
  • Define a function four-square that takes in an
    image and produces a 2x2 arrangement of it like

32
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
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
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
How to accomplish anything
  1. Figure out what you want to do
  2. Do it
  3. Check that you did it right

36
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
The design recipe in practice
  • contract
  • counterchange image (topleft) image(topright)
    -gt 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))

38
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
The result
  • counterchange image (topleft) image(topright)
    -gt 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)))

40
Testing again
  • Change the definition so that it's wrong run the
    tests again and see what happens.

41
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,avoi
    ds "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
    recipeuntil Chapter 12 of HtDP, or Chapter 23
    of PP

42
Exercises
  • Write contracts and test cases, but no
    definitions, for
  • a function named copies-beside that takes in a
    number and an image, and produces that many
    copies of the image side by side
  • a function named pinwheel that takes in an image
    produces a 2x2 rotated thing like
  • a function named checkerboard2 that takes in two
    color names produces a 2x2 checkerboard in
    those colors

43
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
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
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.
Write a Comment
User Comments (0)
About PowerShow.com