Making Programming Easier by Making it More Natural Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University http://www.cs.cmu.edu/~bam bam@cs.cmu.edu 1 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 Brad Myers CMU - HCI Institute 2 Who are the Authors? • Not just professional programmers – Many languages aimed at “part-time” or novice programmers • End User Programming! Brad Myers CMU - HCI Institute 3 Why EUP? By 2005, 55 million end-user programmers Compared to only 2.75 million professional programmers Use spreadsheets, CAD systems, special-purpose scripting and visual languages, etc. These languages are unnecessarily hard to use and prone to errors Errors in spreadsheets and other end-user-created software costs companies millions of dollars Brad Myers CMU - HCI Institute 4 Design of New Languages How make design decisions? Designer’s intuition Similarity to other languages But many have known problems Key concept: If you care about usability and learnability: Can leverage off of what is known and what can be learned about people to guide design decisions Brad Myers CMU - HCI Institute 5 “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 Brad Myers CMU - HCI Institute 6 Examples of Problems The men and women here raise your hands! if is_man(x) and is_woman(x) then raise_hand(x); This issue with “and” applies to other natural languages as well. Find a paint that is not red or orange not (paint.color == red) or paint.color == orange not (paint.color == red or paint.color == orange ) Research shows that these differences between natural languages and computer languages hurt understanding Brad Myers CMU - HCI Institute 7 Why Study This? There are many known problems Little knowledge to guide designs The language which is currently popular seems to have about a 7 year window Fortran, PL/1, Pascal, C, C++, Java, (maybe C# ?) … So new languages are always being created We may influence design by identifying problems Programming is still hard to learn and hard to do Java / C# took some into account We certainly won't if we don't try, or if we don't know what to say! Brad Myers CMU - HCI Institute 8 Gentle Slope Systems Programming in C++ Visual Basic LabView MFC C Programming Difficulty of Use C Programming Basic Program Complexity and Sophistication Goal What we are doing... Studying the People Natural Programming Research Try to provide a more scientific basis for programming language design Apply results of Empirical Studies of Programmers and Human-Computer Interaction to programming language design New studies to fill in gaps Design new programming languages and environments based on these results Brad Myers CMU - HCI Institute 11 Why Would Being Natural be Good? Language should be close to user’s plan “Programming is the process of transforming a mental plan into one that is compatible with the computer.” — Jean-Michel Hoc Example: Inserting item into 3rd place of high score list Easy by Direct Manipulation (in a spreadsheet) Difficult to program: Loop, starting at end of array, shuffle items down, then insert Brad Myers CMU - HCI Institute 12 Why Would Being Natural be Good? #2 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: vs. Let Shape1.FillColor = &H00FF00FF& Brad Myers CMU - HCI Institute 13 Background Research Empirical Studies of Programmers 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 Brad Myers CMU - HCI Institute 15 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-2.cs.cmu.edu/~pane/thesis/ Brad Myers CMU - HCI Institute 16 Natural Programming Studies 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”) Brad Myers CMU - HCI Institute 17 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 programming knowledge But test that the results generalize to adults and programmers Brad Myers CMU - HCI Institute 18 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. 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” Brad Myers CMU - HCI Institute 20 Example Question, 2nd Study Question 4 • Describe in detailed steps what the computer should do to categorize these people into 2 groups of ‘Gold’ and ‘Black’. First name 1 Sandra 2 Bill 3 Cindy 4 Tom 5 Bill 6 Whitney 7 Michael 8 Jay 9 David 10 Will No. Last name Bullock Clinton Crawford Cruise Gates Houston Jordan Leno Letterman Smith Group Brad Myers CMU - HCI Institute First name 1 Sandra 2 Bill 3 Cindy 4 Tom 5 Bill 6 Whitney 7 Michael 8 Jay 9 David 10 Will No. Last name Bullock Clinton Crawford Cruise Gates Houston Jordan Leno Letterman Smith Group Gold Gold Gold Gold Black Gold Gold Black Black Gold 21 Results Rule-based style “If PacMan loses all his lives, its game over.” Some use of Constraint style: “Pacman cannot go through a wall.” Set operations instead of iterations “Subtract 20,000 from all elements in Round 2” — These tend to eliminate control structures Brad Myers CMU - HCI Institute 22 More Results Most arithmetic used natural language style “When PacMan eats a big dot, the score goes up 100.” Operations suggest data as lists, not arrays Objects normally moving “If PacMan hits a wall, he stops.” People don’t make space before inserting so objects remember their own state 2/3 of the first study subjects drew pictures Usually to define the initial state Brad Myers CMU - HCI Institute 23 Implications for New Languages Use event-based style for dynamic events Provide operations on groups of objects Work to minimize the need for control structures and variables Data structures that combine the capabilities of lists + arrays + sets Support simple arithmetic in natural language style (“add 1 to score”) Using mathematical notation such as > < rather than words achieves better accuracy Brad Myers CMU - HCI Institute 29 New Language and System: HANDS Video Brad Myers CMU - HCI Institute 30 Conclusions Can evaluate languages as to extent they are “natural” Can use this technique to answer questions for language designs Based on consistency, learnability, etc. Instead of just using the designer’s intuition Hopefully our data can help Languages can be evaluated just like any other user interface using HCI principles and techniques If you want a useable and learnable programming language, there are data and techniques that can help Brad Myers CMU - HCI Institute 31 Credits Support for this research has come in part from the National Science Foundation under Grant No. IRI-9900452 and Grant No. IIS-9817527 For more information, see: http://www.cs.cmu.edu/~NatProg Brad Myers CMU - HCI Institute 32 Talk Given Using Slide Show Commander Developed as part of the Pebbles Project http://www.cs.cmu.edu/~pebbles Available commercially http://www.slideshowcommander.com/ Making Programming Easier by Making it More Natural Brad A. Myers Human-Computer Interaction Institute School of Computer Science Carnegie Mellon University http://www.cs.cmu.edu/~bam bam@cs.cmu.edu 34