Making JS More Learnable
pamela fox
@pamelafox pamelafox.org
Monday, December 2, 13
Slide 2
Slide 2 text
When did you learn JS?
SURVEY!
Monday, December 2, 13
Slide 3
Slide 3 text
The Path of Learning JS
variables
loops
arrays
objects
prototype
mix-ins
libraries
DOM
futures
generators
closures
Beginner
Expert
with
Monday, December 2, 13
Slide 4
Slide 4 text
Should more people learn JS?
Monday, December 2, 13
Slide 5
Slide 5 text
The Ubiquity of JS
Monday, December 2, 13
Slide 6
Slide 6 text
The Ubiquity of JS
web
server
hardware
mobile
games
Monday, December 2, 13
Slide 7
Slide 7 text
Learning JavaScript is Hard
Monday, December 2, 13
Slide 8
Slide 8 text
How do I know?
Online The “Real” World
Monday, December 2, 13
Teaching JS IRL
http://teaching-materials.org
Monday, December 2, 13
Slide 11
Slide 11 text
I’m surrounded by JS learners!
162,858 challenges completed
300,000 unique programs created
2,600 Members
105 workshops in 2 years
Monday, December 2, 13
Slide 12
Slide 12 text
Let’s Make JS Easier to Learn!
Language Design → Debugging → Documentation
Monday, December 2, 13
Slide 13
Slide 13 text
Language Design
Monday, December 2, 13
Slide 14
Slide 14 text
Language Usability Research
http://www.cs.cmu.edu/~pane/cmu-cs-96-132.html
(A sampling!)
•Variables in math very different from programming variables
•Booleans different from natural language (e.g. inclusive-or vs. exclusive-or)
•Arrays start at 0, people usually count from 1
•Variable names and keywords are case sensitive
•= is often confused with ==
•123 is confused with “123”
•Some variables are passed by reference, other by value
•Having to put “break” in every switch statement causes errors
•Unnecessary syntax: a++ and a+=1
http://www.cs.cmu.edu/~NatProg/OldMarch162007/langeval.html
https://docs.google.com/document/d/1X_V5b0E4qKeSViZcTvpurLb67NfR5GzTUvnh2zZiaWg/edit?usp=sharing
Usability issues for novice programmers:
Monday, December 2, 13
Slide 15
Slide 15 text
Language Usability
Inconsistency with External Knowledge
Monday, December 2, 13
Slide 16
Slide 16 text
Language Usability
Inconsistent syntax
Monday, December 2, 13
Slide 17
Slide 17 text
Language Usability
Non-intuitive syntax
Monday, December 2, 13
Slide 18
Slide 18 text
Language Usability
Unnecessary syntax (Less is More)
Monday, December 2, 13
Slide 19
Slide 19 text
JS Language Usability?
• All of those issues were inherited from other
languages
• JS usability itself is not well researched :-(
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.133.4831&rep=rep1&type=pdf
Monday, December 2, 13
Slide 20
Slide 20 text
(How you can) Improve the language
http://www.ecmascript.org/dev.php
“Development of ECMAScript standards is an open
process, and we encourage public participation.”
Monday, December 2, 13
JSHint in online tools
repl.it
jsbin.com
Monday, December 2, 13
Slide 25
Slide 25 text
JSHint on Khan Academy
if (i == 0) {
}
var i = 2;
if (i == 0) {
}
errors
warnings
best
practices
var myName = “spaghetti
Monday, December 2, 13
Slide 26
Slide 26 text
Improving JSHint messages
rect(193,139,,30);
Expected an identifier and instead saw ','.
I thought you were going to type an identifier but you typed ‘,’!
I think you meant to type a value or variable name before that comma?
Original
Conversational
Specific
+ Actionable
Monday, December 2, 13
Slide 27
Slide 27 text
rect(80, 70, 60, 240,);
I thought you were going to type an identifier but
you typed )!
→
I think you either have an extra comma or a missing
argument?
var x = 5;
x+x=1;
Bad assignment!
→
The left side of an assignment must be a single
variable name, not an expression.
140= 141 + 142; Bad assignment!
text;()
I thought you were going to type an assignment or
function call but you typed an expression instead!
More Newbie Syntax Errros
Monday, December 2, 13
Slide 28
Slide 28 text
(How you can) Improve JSHint
https://github.com/jshint/jshint/blob/2.x/src/messages.js
•Improve messages
•Add more specific
messages
•Translate messages
Monday, December 2, 13
Slide 29
Slide 29 text
More linting: “BabyHint”
elipse(10, 10, 20, 30);
spelling
wrong
arguments
ellipse(1, 1, 20, 30, 5);
https://gist.github.com/pamelafox/7745401
Monday, December 2, 13
Slide 30
Slide 30 text
(How you can) Improve Linters
https://github.com/nzakas/eslint
Add babyhint functionality to JSHint or ESLint?
Monday, December 2, 13
Slide 31
Slide 31 text
The Browser “IDE”
Monday, December 2, 13
Slide 32
Slide 32 text
The Browser “IDE”
Why is hplogo a global var??
What does undefined mean??
But I used the right method?!
Monday, December 2, 13
Slide 33
Slide 33 text
Improving the Browser IDE
http://anton.kovalyov.net/p/js-typos/
Monday, December 2, 13
Slide 34
Slide 34 text
(How you can) Improve Browsers
http://www.chromium.org/developers
http://codefirefox.org/
Patch the browser itself
Make a dev tool plugin
http://developer.chrome.com/extensions/devtools.html
http://blog.mozilla.org/addons/2009/01/28/how-to-develop-a-firefox-extension/
Write a blog post
Monday, December 2, 13
Slide 35
Slide 35 text
Documentation
Monday, December 2, 13
Slide 36
Slide 36 text
Where are the JS docs?
Monday, December 2, 13
Slide 37
Slide 37 text
(How you can) Improve the docs
Mozilla Developer Network
Just click “Edit”
W3schools
Click “Report Error”
Monday, December 2, 13
Slide 38
Slide 38 text
Let’s Make JS Easier to Learn!
Language Design → Debugging → Documentation
Monday, December 2, 13