Towards More Natural Functional Programming Languages - PowerPoint PPT Presentation

About This Presentation
Title:

Towards More Natural Functional Programming Languages

Description:

The User Interface of Programming Languages. Programming ... Cindy. Crawford. 4. Tom. Cruise. 5. Bill. Gates. 6. Whitney. Houston. 7. Michael. Jordan. 8. Jay ... – PowerPoint PPT presentation

Number of Views:192
Avg rating:3.0/5.0
Slides: 54
Provided by: bradm4
Learn more at: http://www.cs.cmu.edu
Category:

less

Transcript and Presenter's Notes

Title: Towards More Natural Functional Programming Languages


1
Towards MoreNatural Functional Programming
Languages
  • Brad A. Myers
  • Human-Computer Interaction Institute
  • School of Computer Science
  • Carnegie Mellon University
  • http//www.cs.cmu.edu/bam
  • bam_at_cs.cmu.edu

2
The User Interface of Programming Languages
  • Programming is a human activity
  • Want to improve the ability of people to program
  • It makes sense to look at the human side

3
  • Millions for compilers but hardly a penny for
    understanding human programming language use.
    Now, programming languages are obviously
    symmetrical, the computer on one side, the
    programmer on the other. In an appropriate
    science of computer languages, one would expect
    that half the effort would be on the computer
    side, understanding how to translate the
    languages into executable form, and half on the
    human side, understanding how to design languages
    that are easy or productive to use.... The human
    and computer parts of programming languages have
    developed in radical asymmetry.
  • Allen Newell and Stuart Card, 1985

4
What is Usability?
  • Usability The effectiveness, efficiency, and
    satisfaction with which users can achieve tasks
    in a particular environment of a product.
  • Components
  • Learnability Easy to learn so users can get
    started rapidly.
  • Effectiveness Experts can use it effectively and
    with high productivity.
  • Low Error rate Users make few errors.
  • Satisfaction Pleasant to use. No frustrations
    for users.
  • Similar to motivations for functional languages

5
Why Human Computer Interaction?
  • The field of Human Computer Interaction studies
    how to improve and evaluate usability
  • Data, knowledge that can guide designs
  • To make systems more usable
  • Techniques for evaluating usability
  • So claims can be substantiated
  • So improvements can be made

6
Who are the Programmers?
7
Design of New Languages
  • How make design decisions?
  • Based on math, logic, type theory
  • Designers intuition or sense of aesthetics
  • Similarity to other languages
  • But many have known problems
  • Key concept
  • If you care about usability
  • Can leverage off of what is known andwhat can be
    learned about peopleto guide design decisions

8
What we are doing...
Studying the People
9
Examples of Problems
The men and women here raise your hands!
if ((isMan x) (isWoman x)) then (raise_hands
x) else ()
  • (This issue with and applies to other natural
    languages as well.)

( )
( )
if (( not isRed isBlue ) x) then buy x else
()
  • Research shows that these differences between
    natural languages and computer languages hurt
    understanding

10
My Research Goals
  • Make programming significantly easier to learn
    and more effective for non-professional
    programmers and beginners
  • Try to provide a more objective basis for
    usability decisions for programming language
    design
  • Apply results of Empirical Studies of
    Programmers, Psychology of Programming, and
    Human-Computer Interaction to programming
    language design
  • New studies
  • Design new programming languages and environments
    based on these results

11
Multiple Criteria
  • Focusing on learnability and naturalness for
    beginners
  • Less emphasis
  • Scalability
  • Provability
  • Efficiency
  • Mathematical or Logic properties
  • Similarity to other familiar languages
  • etc.

12
Gentle Slope Systems
DifficultyofUse
Program Complexity and Sophistication
13
Gentle Slope Systems
Programming in C
MFC
DifficultyofUse
Program Complexity and Sophistication
14
Gentle Slope Systems
Programming in C
FunctionalLanguages?
MFC
UI libraries
DifficultyofUse
Program Complexity and Sophistication
15
Gentle Slope Systems
Visual Basic
Programming in C
FunctionalLanguages?
C Programming
MFC
UI libraries
DifficultyofUse
Basic
Program Complexity and Sophistication
16
Gentle Slope Systems
Visual Basic
Programming in C
FunctionalLanguages?
C Programming
MFC
UI libraries
DifficultyofUse
Basic
My Goal
Program Complexity and Sophistication
17
What is Natural Programming?
  • Attempt to make programming closer to the way
    people think
  • Make programming more natural
  • First, have to find out how people think about
    algorithms, data structures, etc.
  • Note Not natural language
  • Still creating a formal language

18
Why Might Being Natural be Good?
  • Programming is the process of transforming a
    mental plan into one that is compatible with the
    computer. Jean-Michel Hoc
  • So process might be easier if transformation is
    smaller
  • Closeness of mapping
  • "The closer the programming world is to the
    problem world, the easier the problem-solving
    ought to be. Conventional textual languages are
    a long way from that goal." Green and Petre

19
Why Might Being Natural be Good?
  • Example
  • Inserting item into 3rd place of high score list
  • Conventional Languages
  • Loop, starting at end of array, shuffle items
    down, then insert

20
Why Might Being Natural be Good?
  • Directness (as in Direct Manipulation)
  • Distance between one's goals and the actions
    required by the system to achieve those goals.
    Hutchins, Hollan and Norman

vs. VB Let Shape1.FillColor
H00FF00FF ML SetColor ( Shape1, 0x00FF00FF )
21
Background Research
  • Empirical Studies of Programmers, Psychology of
    Programming, and HCI results not being used in
    the design of new languages
  • 30 years of research on what makes languages hard
    to learn and error-prone
  • Java / C looping, etc.
  • Summarized in our comprehensive tech report
  • John Pane and Brad Myers, Usability Issues in
    the Design of Novice Programming Systems TR
    CMU-CS-96-132. Aug, 1996.http//www.cs.cmu.edu/p
    ane/cmu-cs-96-132.html

22
Examples of Problems Identified
  • Promote Locality and Avoid Hidden Dependencies
  • Type definitions often are far from the use
  • Code readability is of key importance
  • Dont try to reduce keystrokes if makes less
    readable
  • Inheritance and object-oriented design are very
    difficult
  • Beware of misleading appearances
  • When novices and experts mis-read code
  • Avoid subtle distinctions in syntax
  • E.g., ab vs. ab () vs. vs. gt vs. gt
    vs. -gt

23
More Examples
  • People expect consistency with external
    representations and usage (math, English, etc.)
  • People will search for an analogue in their
    experience that is similar to the syntax
  • and aa1 a2 vs. 2a 1ltalt10
  • ML is unary negative, - for subtraction 5 -
    2
  • So, if different meaning, should have different
    presentation
  • Significant difficulties in finding bugs due to
    invisible data, dependencies, and control flow

24
HCI Methods for Analyzing Languages
  • Analyze languages as user interfaces
  • Greens Cognitive Dimensions
  • Green and Petre, 1996, Usability Analysis of
    VP Environments A Cognitive Dimensions
    Framework. Journal of VLC, 7(2) 131-174
  • 13 dimensions
  • Nielsens heuristic analysis principles
  • Nielsen, J., Usability Engineering. 1993,
    Boston Academic Press
  • 10 principles
  • Can also perform usability studies for specific
    issues

25
Consistency
  • Both a Cognitive Dimension and a Heuristic
    Analysis principle
  • C uses the word "static" to mean at least 3
    different things
  • In C, can use int a,b to define globals or
    locals, but not as procedure parameters
  • Should be able to copy code and use the same code
    elsewhere
  • In Visual Basic, to assign something you use
    unless is an object, in which case you use
    Set and "foo 15" vs. "Set foo object
  • ML fun f x 0 vs. case e of x gt 0

26
Error-Proneness
  • HCI Principle Prevent errors
  • C and C array bounds errors
  • Requiring the "break" in each branch of C, C
    switch statements causes many errors (still in
    Java, fixed in C)
  • Small typos can result in compilable programs
    that perform incorrectly, e.g., "" for "
    or"x-3 vs. "x-3 orfun f(SOME _)... (a
    constructor pattern) vs.fun f(SOME_)... (a
    variable)

27
Good Error Messages
  • Should be clear, helpful, precise, constructive
  • Not syntax error
  • In C, so much flexibility, compiler often
    doesnt know where error is
  • Similar problems with type inference systems
  • SML/NJ
  • stdIn30.1-30.4 Error operator and operand don't
    agree tycon mismatch
  • operator domain ?.t
  • operand ?.t
  • in expression
  • f B

28
Closeness of Mapping
  • HCI principle Speak the User's Language
  • Expressions of algorithms close to the way users
    think of them
  • Also, syntactic Issues
  • C uses "void" to mean "none", "char" to mean
    8-bit number, ...
  • Visual Basic uses "Dim" to declare variables and
    "wend" to end while loops
  • Arrays start at 0 whereas people think of
    counting from 1
  • Case sensitivity

29
Viscosity
  • Resistance to local change
  • To change parameters of a function in C, have
    to edit .h file and .cpp file, plus all call
    sites
  • Changing an if statement into a do statement
    was difficult in early structure editors
  • VLs are very difficult due to layout issues
  • May have to reposition all lines and boxes to
    make room and neaten resulting drawing
  • May need to disconnect and reconnect many wires
  • Need for correct indenting may make Haskell
    programs resistant to editing
  • But good editor can help

30
Less is More
  • HCI principle (keep it simple)
  • C, C have 16 levels of precedence that have to
    be memorized, some of which are left-associative
    and some are right-associative. Consider
    abcdefgwhich is a legal
    statement in C and C
  • Deep nesting in functional languages
  • Too many parentheses

31
Help the user get started with the system
  • Small things should be simple
  • Programs that do small things must stilloften be
    very large, e.g., creating awindow containing a
    single red rectangle
  • The 2-pages needed in Motif to do Hello World
  • zero lines in Visual Basic
  • In Java, it still requires
  • class HelloWorldApp
  • public static void main(String args)
  • System.out.println("Hello World!")
  • Note 3 kinds of parentheses, 9 special words
  • ML print "Hello World!"

32
Other Issues
  • Many more, seehttp//www.cs.cmu.edu/NatProg/lan
    geval.html
  • You can send me examples from each others
    systems!
  • But these are mainly good for analysis
  • Given a design question, how answer it?

33
Our Research
  • Lots of gaps in prior research on people and
    programming
  • Develop knowledge that can be used in design
  • Ph.D. thesis of John Pane
  • Available at
  • http//www.cs.cmu.edu/pane/thesis/
  • Evaluate
  • How people express algorithms and think about
    tasks
  • Vocabulary and notations used
  • Related to the HCI principles of know the user,
    task analysis, and closeness of mapping

34
Our Studies so far
  • How people naturally express programming concepts
    and algorithms
  • 1) Nine scenes from PacMan
  • 2) Transforming and calculating data in a
    spreadsheet
  • Specific issues of language design
  • 3) Selecting specific objects from a group
    (and, or, not)

35
Experimental Design
  • Question should not bias the answer
  • So use pictures instead of textual descriptions
  • Concentrate on kids, non-programmers
  • Subjects should not be tainted by existing
    programming languages
  • Tested that the results generalize to adults and
    programmers

36
Study 1
  • Usually Pacman moves like this.
  • Now let's say we add a wall.
  • Pacman moves like this.
  • Not like this.

Do this Write a statement that summarizes how I
(as the computer) should move Pacman in relation
to the presence or absence of other things.
37
Second Study
  • Whether similar results from other domains and
    with adults
  • Developed 11 questions with scenarios using
    spreadsheets
  • To test database access and operations
  • More conventionally computational

38
Example Question, 2nd Study
Question 4
  • Describe in detailed steps what the computer
    should do tocategorize these people into 2
    groups of Gold and Black.









Firstname
Lastname
Firstname
Lastname

No.



Group

No.



Group



1

Sandra

Bullock


1

Sandra

Bullock

Gold

2

Bill

Clinton


2

Bill

Clinton

Gold

3

Cindy

Crawford

3

Cindy

Crawford


Gold

4

Tom

Cruise


4

Tom

Cruise

Gold

5

Bill

Gates


5

Bill

Gates

Black

6

Whitney

Houston

6

Whitney

Houston


Gold

7

Michael

Jordan


7

Michael

Jordan

Gold

8

Jay

Leno


8

Jay

Leno

Black

9

David

Letterman

9

David

Letterman


Black

10

Will

Smith


10

Will

Smith

Gold
39
Results
  • Rule-based style If PacMan loses all his lives,
    its game over.
  • Some use of Constraint style Pacman cannot go
    through a wall.
  • Aggregate operations instead of iterations The
    monsters turn blue and run away Subtract
    20,000 from all elements in Round 2
  • These tend to eliminate control structures

40
More Results
  • The words AND and THEN often used for
    sequencing instead of as a logical operator The
    monsters turn color and start to back up.
  • Boolean expression (AND, OR) not common
  • Usually had mutually exclusive rulesIf I press
    the up arrow, PacMan goes up. If I press the
    down arrow, PacMan goes down,
  • General case first, then exceptions When you
    encounter a ghost, it should kill you. But if
    you get a big pill first you can eat them.

41
Yet More Results
  • Most arithmetic used natural language styleWhen
    PacMan eats a big dot, the score goes up 100.
  • Operations suggest data as lists, not arrays
  • People dont make space before inserting
  • Objects normally moving If PacMan hits a wall,
    he stops.
  • so objects remember their own state
  • 2/3 of the first study subjects drew pictures
  • Usually to define the initial state

42
Third Study Select Objects from a Group
  • Concentrate on a known problematic area
  • Use of AND, OR, NOT
  • Often eliminated from Web searching
  • Newsweek reports that less than 6 of users
    manage to use and, or, , -
  • Still dominant in all programming languages
  • First generate queries given results
  • Then, answer queries
  • Form-based and Textual formats
  • Order was counter-balanced

43
Generate Queries
44
Answer Queries
45
Results
  • Using unless did not help accuracyselect the
    objects that are blue unless the objects are
    squarevs.select the objects that match blue
    and not square
  • And was a Boolean conjunction sometimesselect
    the objects that match blue and
    circlevs.select the objects that match blue
    and the objects that match circle
  • Precedence of not variedselect the objects
    that match not red and square 64 interpreted
    as (not red) and square select the objects
    that match not triangle or green 67
    interpreted as not (triangle or green)

46
More results
  • 2-D forms helped for generation
  • 94 correct with match forms, vs.85 correct
    with text (plt.0001)

(blue and not square) or (circle and not green)
47
Implications for New Languages
  • For increased usability for novices
  • Use event-based style for dynamic events
  • Work to minimize the need for control structures
    and variables
  • Provide operations on groups of objects
  • Data structures that combine the capabilities
    oflists arrays sets
  • Support simple arithmetic in natural language
    style (add 1 to score)
  • Avoid the use of the word and altogether

48
New Language and System HANDS
Human-centered Advances for Novices to Develop
Software
  • Video

49
Properties of HANDS
  • Goal Allow children age 10 to createinteractive
    games and simulations
  • Programming in the small (in the tiny)
  • Event based computation model
  • Metaphor of agent manipulating cards
  • All data is visible as properties of the cards
  • All operations work on singletons or lists
  • No distinction in syntax
  • Can generate lists on the fly with queries
  • Minimize need for control structures
  • Minimize need for local variables

50
More Properties of Hands
  • Verbose Language
  • Easier to read
  • No precedence
  • Does use parentheses
  • But just one kind!
  • Environment provide lots of help with syntax and
    graphics
  • Tries to be extremely consistent, and also apply
    other HCI rules
  • For example, combines IF, CASE (switch), andCOND
    (from Lisp) into one construct

51
Conclusions
  • Much more research needed on the human side of
    programming
  • Usability of languages and environments can be
    improved
  • Claims about usability can be tested
  • Languages can be evaluated using HCI principles
    and techniques
  • If you want a useable and learnable programming
    language, there are data and techniques available
    that can help.

52
Credits
  • Support for this research has come in part from
    the National Science Foundation underGrant No.
    IRI-9900452
  • and
  • Grant No. IIS-9817527
  • For more information, see
  • http//www.cs.cmu.edu/NatProg

53
Towards MoreNatural FunctionalProgramming
Languages
Thank You!
  • Brad A. Myers
  • Human-Computer Interaction Institute
  • School of Computer Science
  • Carnegie Mellon University
  • http//www.cs.cmu.edu/bam
  • http//www.cs.cmu.edu/NatProg
  • bam_at_cs.cmu.edu
Write a Comment
User Comments (0)
About PowerShow.com