1 towards more natural functional programming languages brad a. myers human-computer interaction...

53
1 Towards More Natural Functional Programming Languages Brad A. Myers Brad A. Myers Human-Computer Interaction Human-Computer Interaction Institute Institute School of Computer Science School of Computer Science Carnegie Mellon University Carnegie Mellon University http://www.cs.cmu.edu/~bam http://www.cs.cmu.edu/~bam [email protected] [email protected]

Post on 21-Dec-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

1

Towards MoreNatural Functional Programming Languages

Towards MoreNatural Functional Programming Languages

Brad A. MyersBrad A. MyersHuman-Computer Interaction InstituteHuman-Computer Interaction InstituteSchool of Computer ScienceSchool of Computer ScienceCarnegie Mellon UniversityCarnegie Mellon University

http://www.cs.cmu.edu/~bamhttp://www.cs.cmu.edu/[email protected]@cs.cmu.edu

Page 2: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 2ICFP’02ICFP’02

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

Programming is a human activity Want to improve the ability of people to program It makes sense to look at the human side

Page 3: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 3ICFP’02ICFP’02

— Allen Newell and Stuart Card, 1985— Allen Newell and Stuart Card, 1985

“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.”

“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.”

Page 4: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 4ICFP’02ICFP’02

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

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

Page 5: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 5ICFP’02ICFP’02

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

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

Page 6: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 6ICFP’02ICFP’02

Who are the Programmers?

• Not just professional programmers anymore By 2005, 55 million end-user programmers

Compared to only 2.75 million professional programmers

• Not just professional programmers anymore By 2005, 55 million end-user programmers

Compared to only 2.75 million professional programmers

Page 7: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 7ICFP’02ICFP’02

Design of New Languages

How make design decisions? Based on math, logic, type theory Designer’s 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 people

to guide design decisions

How make design decisions? Based on math, logic, type theory Designer’s 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 people

to guide design decisions

Page 8: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

8

What we are doing...

Studying the People

Page 9: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 9ICFP’02ICFP’02

if ((isMan x) && (isWoman x)) then (raise_hands x) else ()if ((isMan x) && (isWoman x)) then (raise_hands x) else ()

( ) ( )

Research shows that these differences between natural languages and computer languages hurt understanding

Research shows that these differences between natural languages and computer languages hurt understanding

Examples of Problems

The men and women here raise your hands!The men and women here raise your hands!

Buy a paint that is not red or blueBuy a paint that is not red or blueif (( not isRed || isBlue ) x) then buy x else ()if (( not isRed || isBlue ) x) then buy x else () ( ) ( )

(This issue with “and” applies to other natural languages as well.)

(This issue with “and” applies to other natural languages as well.)

Page 10: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 10ICFP’02ICFP’02

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

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

Page 11: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 11ICFP’02ICFP’02

Multiple Criteria

Focusing on learnability and naturalness for beginners

Less emphasis: Scalability Provability Efficiency Mathematical or Logic properties Similarity to other familiar languages etc.

Focusing on learnability and naturalness for beginners

Less emphasis: Scalability Provability Efficiency Mathematical or Logic properties Similarity to other familiar languages etc.

Page 12: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Gentle Slope Systems

Difficultyof

Use

Program Complexity and Sophistication

Page 13: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Gentle Slope Systems

Difficultyof

Use

Programming in C++

MFC

Program Complexity and Sophistication

Page 14: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Gentle Slope Systems

Difficultyof

Use

Programming in C++

MFC

Program Complexity and Sophistication

FunctionalLanguages?

UI libraries

Page 15: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Gentle Slope Systems

Difficultyof

Use

Programming in C++

MFC

Program Complexity and Sophistication

FunctionalLanguages?

UI libraries

Visual Basic

Basic

C++ Programming

Page 16: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Gentle Slope Systems

Difficultyof

Use

Programming in C++

MFC

Program Complexity and Sophistication

FunctionalLanguages?

UI libraries

Visual Basic

Basic

C Programming

My Goal

Page 17: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 17ICFP’02ICFP’02

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

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

Page 18: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 18ICFP’02ICFP’02

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

“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

Page 19: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 19ICFP’02ICFP’02

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

Example: Inserting item into 3rd place of high score list Conventional Languages:

Loop, starting at end of array, shuffle items down, then insert

Page 20: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 20ICFP’02ICFP’02

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

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

Example: Example:

vs.

VB: Let Shape1.FillColor = &H00FF00FF&

ML: SetColor ( Shape1, 0x00FF00FF )

vs.

VB: Let Shape1.FillColor = &H00FF00FF&

ML: SetColor ( Shape1, 0x00FF00FF )

Page 21: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 21ICFP’02ICFP’02

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/~pane/cmu-cs-96-132.html

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/~pane/cmu-cs-96-132.html

Page 22: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 22ICFP’02ICFP’02

Examples of Problems Identified

Promote Locality and Avoid Hidden Dependencies Type definitions often are far from the use

Code readability is of key importance Don’t 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., a=b vs. a==b; () vs. [] vs. {}; >= vs. => vs. ->

Promote Locality and Avoid Hidden Dependencies Type definitions often are far from the use

Code readability is of key importance Don’t 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., a=b vs. a==b; () vs. [] vs. {}; >= vs. => vs. ->

Page 23: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 23ICFP’02ICFP’02

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”; a=a+1; a=2 vs. 2=a; 1<a<10; 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

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”; a=a+1; a=2 vs. 2=a; 1<a<10; 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

Page 24: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 24ICFP’02ICFP’02

HCI Methods for Analyzing Languages

Analyze languages as user interfaces Green’s Cognitive Dimensions

— Green and Petre, 1996, “Usability Analysis of VP Environments: A ‘Cognitive Dimensions Framework’. Journal of VL&C, 7(2): 131-174

13 dimensions

Nielsen’s heuristic analysis principles— Nielsen, J., Usability Engineering. 1993, Boston: Academic

Press 10 principles

Can also perform usability studies for specific issues

Analyze languages as user interfaces Green’s Cognitive Dimensions

— Green and Petre, 1996, “Usability Analysis of VP Environments: A ‘Cognitive Dimensions Framework’. Journal of VL&C, 7(2): 131-174

13 dimensions

Nielsen’s heuristic analysis principles— Nielsen, J., Usability Engineering. 1993, Boston: Academic

Press 10 principles

Can also perform usability studies for specific issues

Page 25: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 25ICFP’02ICFP’02

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 => 0”

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 => 0”

Page 26: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 26ICFP’02ICFP’02

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)

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)

Page 27: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 27ICFP’02ICFP’02

Good Error Messages

Should be: clear, helpful, precise, constructive Not “syntax error” In C++, so much flexibility, compiler often doesn’t

know where error is Similar problems with type inference systems

SML/NJ:stdIn:30.1-30.4 Error: operator and operand don't agree [tycon mismatch]

operator domain: ?.t

operand: ?.t

in expression:

f B

Should be: clear, helpful, precise, constructive Not “syntax error” In C++, so much flexibility, compiler often doesn’t

know where error is Similar problems with type inference systems

SML/NJ:stdIn:30.1-30.4 Error: operator and operand don't agree [tycon mismatch]

operator domain: ?.t

operand: ?.t

in expression:

f B

Page 28: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 28ICFP’02ICFP’02

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

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

Page 29: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 29ICFP’02ICFP’02

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

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

Page 30: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 30ICFP’02ICFP’02

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:

a=b+=c=+d*e+++f==gwhich is a legal statement in C++ and C

Deep nesting in functional languages “Too many parentheses”

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:

a=b+=c=+d*e+++f==gwhich is a legal statement in C++ and C

Deep nesting in functional languages “Too many parentheses”

Page 31: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 31ICFP’02ICFP’02

Help the user get started with the system

Small things should be simple Programs that do small things must still

often 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!"

Small things should be simple Programs that do small things must still

often 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!"

Page 32: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 32ICFP’02ICFP’02

Other Issues

Many more, see:http://www.cs.cmu.edu/~NatProg/langeval.html

You can send me examples from each other’s systems!

But these are mainly good for analysis Given a design question, how answer it?

Many more, see:http://www.cs.cmu.edu/~NatProg/langeval.html

You can send me examples from each other’s systems!

But these are mainly good for analysis Given a design question, how answer it?

Page 33: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 33ICFP’02ICFP’02

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”

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”

Page 34: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 34ICFP’02ICFP’02

Our Studies so far

How people naturally express programming concepts and algorithms1) Nine scenes from PacMan

2) Transforming and calculating data in a spreadsheet

Specific issues of language design3) Selecting specific objects from a group (“and”, “or”, “not”)

How people naturally express programming concepts and algorithms1) Nine scenes from PacMan

2) Transforming and calculating data in a spreadsheet

Specific issues of language design3) Selecting specific objects from a group (“and”, “or”, “not”)

Page 35: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 35ICFP’02ICFP’02

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

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

Page 36: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Usually Pacman moves like this.

Now let's say we add a wall.

Pacman moves like this.

Not like this.

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.

Study 1

Page 37: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 37ICFP’02ICFP’02

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”

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”

Page 38: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 38ICFP’02ICFP’02

Example Question, 2nd Study

No.

Firstname

Lastname

Group

1 Sandra Bullock 2 Bill Clinton 3 Cindy Crawford 4 Tom Cruise 5 Bill Gates 6 Whitney Houston 7 Michael Jordan 8 Jay Leno 9 David Letterman 10 Will Smith

Question 4• Describe in detailed steps what the computer should do to

categorize these people into 2 groups of ‘Gold’ and ‘Black’.

No.

Group

1 Sandra Bullock Gold 2 Bill Clinton Gold 3 Cindy Crawford Gold 4 Tom Cruise Gold 5 Bill Gates Black 6 Whitney Houston Gold 7 Michael Jordan Gold 8 Jay Leno Black 9 David Letterman Black 10 Will Smith Gold

Firstname

Lastname

Page 39: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 39ICFP’02ICFP’02

Results

Rule-based style“If PacMan loses all his lives, its game over.”

Some use of Constraint style: “Pacman cannot go through a wall.”

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

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

Page 40: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 40ICFP’02ICFP’02

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

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 rules

“If 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.”

Boolean expression (AND, OR) not common Usually had mutually exclusive rules

“If 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.”

Page 41: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 41ICFP’02ICFP’02

Yet More Results

Most arithmetic used natural language style“When PacMan eats a big dot, the score goes up 100.”

Most arithmetic used natural language style“When PacMan eats a big dot, the score goes up 100.”

Operations suggest data as lists, not arrays People don’t 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

Operations suggest data as lists, not arrays People don’t 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

Page 42: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 42ICFP’02ICFP’02

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

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

Page 43: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 43ICFP’02ICFP’02

Generate Queries

Page 44: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 44ICFP’02ICFP’02

Answer Queries

Page 45: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 45ICFP’02ICFP’02

Results

Using “unless” did not help accuracy“select the objects that are blue unless the objects are square”vs.“select the objects that match blue and not square

Using “unless” did not help accuracy“select the objects that are blue unless the objects are square”vs.“select the objects that match blue and not square

“And” was a Boolean conjunction sometimes“select the objects that match blue and circle”vs.“select the objects that match blue and the objects that match circle”

Precedence of “not” varied“select 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)”

“And” was a Boolean conjunction sometimes“select the objects that match blue and circle”vs.“select the objects that match blue and the objects that match circle”

Precedence of “not” varied“select 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)”

Page 46: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 46ICFP’02ICFP’02

More results

2-D forms helped for generation 94% correct with match forms, vs.

85% correct with text (p<.0001)

2-D forms helped for generation 94% correct with match forms, vs.

85% correct with text (p<.0001)

(blue and not square) or (circle and not green)

Page 47: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 47ICFP’02ICFP’02

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 of

lists + arrays + sets Support simple arithmetic in natural language style

(“add 1 to score”) Avoid the use of the word “and” altogether

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 of

lists + arrays + sets Support simple arithmetic in natural language style

(“add 1 to score”) Avoid the use of the word “and” altogether

Page 48: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 48ICFP’02ICFP’02

New Language and System: HANDS

Video

Human-centered Advances for Novices to Develop Software

Page 49: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 49ICFP’02ICFP’02

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

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

Page 50: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 50ICFP’02ICFP’02

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), and

COND (from Lisp) into one construct

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), and

COND (from Lisp) into one construct

Page 51: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 51ICFP’02ICFP’02

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.

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.

Page 52: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

Brad MyersBrad MyersCMU - HCI InstituteCMU - HCI Institute 52ICFP’02ICFP’02

Credits

Support for this research has come in part from the National Science Foundation under

Grant No. IRI-9900452

andGrant No. IIS-9817527

For more information, see:

http://www.cs.cmu.edu/~NatProg

Support for this research has come in part from the National Science Foundation under

Grant No. IRI-9900452

andGrant No. IIS-9817527

For more information, see:

http://www.cs.cmu.edu/~NatProg

Page 53: 1 Towards More Natural Functional Programming Languages Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University

53

Towards MoreNatural FunctionalProgramming Languages

Towards MoreNatural FunctionalProgramming Languages

Brad A. MyersBrad A. MyersHuman-Computer Interaction InstituteHuman-Computer Interaction InstituteSchool of Computer ScienceSchool of Computer ScienceCarnegie Mellon UniversityCarnegie Mellon University

http://www.cs.cmu.edu/~bamhttp://www.cs.cmu.edu/~bamhttp://www.cs.cmu.edu/~NatProghttp://www.cs.cmu.edu/[email protected]@cs.cmu.edu