

JavaScript at Khan Academy - michaelkscott
http://ejohn.org/blog/javascript-as

======
brown9-2
_The prospect of teaching the JavaScript language as a first language is
actually really exciting. Teaching prototypal inheritance to experienced
classical-inheritance-using developers is normally rather frustrating (and
results in many libraries springing up attempting to replicate the classical
style of inheritance in JavaScript, which is a whole realm of weirdness in-
and-of itself). Teaching prototypal inheritance to someone who has never seen
any form of inheritance before will decidedly be an easier task._

But does this result in a better outcome for the student?

How many other commonly used programming languages use prototypal inheritance?

~~~
SeanLuke
In answer to your first question. Prototypes are a much _much_ simpler concept
than classes and instances. In prototypes, you create an object X which is
"just like object Y but with the following differences". No class
declarations, no instantiation, no constructors -- just factory functions.
Prototypes are also easily understood by people who have grasped the concept
of dictionaries. No need to explain why you have dictionaries and also have
classes.

Prototypes also have some niceties. They are very memory compact, unlike
classes and instances. They are elegantly dynamic -- you can add and delete
methods and variables, and even change who your prototype is at runtime.
Methods in prototypes are very similar to functions, so you don't have to
explain the distinctions there.

I think the main problem is that Javascript is such a screwed up language that
it has soured people forever on prototype OO and no amount of semantic
elegance will fix that.

In answer to your second question, here's the list of languages I know of.
Only two are "mainstream", but in a field (CS) where quality is all too often
inversely related to popularity, I'm not sure if that's a helpful metric.

1\. Self

2\. NewtonScript

3\. Lua (via metamethods)

4\. io

5\. IIRC Python implements OO with something approximating prototypes
internally but covers them with a class-based sheen when presented to the
developer.

~~~
tantalor
_IIRC Python implements OO with something approximating prototypes internally
but covers them with a class-based sheen when presented to the developer._

One notable difference is that `foo.method` is bound to `foo` in python, but
unbound in JavaScript. This leads to lots of `foo.method.bind(foo)` because
the former didn't DWIM.

~~~
198d
I've been writing Python for maybe 3 months now and as I started digging into
the OO stuff, I commented to a few developers about how it 'felt' a lot like
javascript and they nearly took my head off. Is there any material you (or
anyone for that matter) can point me to that might help solidify my argument?

~~~
natedub
Ian Bicking gave a talk on the similarities and differences between Python and
Javascript that might be helpful, but it's pretty high level:
[http://blip.tv/pycon-us-
videos-2009-2010-2011/pycon-2011-jav...](http://blip.tv/pycon-us-
videos-2009-2010-2011/pycon-2011-javascript-for-people-who-know-
python-4900851)

The key similarities in my mind are:

1) In both python and javascript, the class and prototype are exposed and can
be called explicitly if desired:

    
    
      MyClass.method(my_instance, arg1, arg2)
    
      MyClass.prototype.method.call(my_instance, arg1, arg2);
    

2) Python will automatically bind methods when you retrive them from an
instance. Unless you explicitly bind a function in JS, the "this" parameter is
specified at call time: whatever comes before the dot is used as "this".
Ultimately they're both first class objects and the difference to the
developer is notation:

    
    
      bound_method = my_instance.method
    
      bound_method = my_instance.method.bind(my_instance);
    

3) Attribute lookups in Python behave very similarly to property lookups in
Javascript. Python has a modified resolution order for searching for an
attribute through its list of parent classes. Javascript will look for an
attribute in a series of prototypes (since in JS, an instance's prototype is
just an object, so it too can have a prototype). Python is superior here
because it supports multiple inheritance, but overall the resolution behaviour
is essentially the same.

Can anyone think of any other common ground?

------
vasco
With Javascript being the mess that it is I doubt it would be a good starting
language, it has too much idiosyncrasies. Most of the post seemed to be
excusing Javascript's faults and trying to convince me that I have a problem
with said faults because I've been exposed to "better" programming languages.
_No shit_.

To be fair, Javascript is the easiest language to teach through a website, but
that's it. The goal shouldn't be to make the teacher's life easy rather then
providing the right tools for the student.

~~~
rictic
Don't underestimate the power of the web though. For a new student/user,
there's a big difference between step 1 being "click this link" rather than
"follow this intimidating installation process".

Javascript is not ideal, but it's quite good, and it's there, already running
in a sandbox on the student's machine.

------
iandanforth
JS is a terrible way to teach CS _and_ it's a terrible first language to learn
programming.

CS requires a deeper understanding that JS gloses over (obviously) and
programming in general can be more easily learned in either a cleaner (python)
or more rigorous (java) language. I'm only a few years into my programming
career and vividly remember trying dozens of tutorials in half a dozen
languages before deciding on really learning through Python. If I were to rank
languages to start with they would look like this:

Goal: Learn to Program

Python, Ruby, Java, PHP - yes, really, JS

Goal: Learn CS

Java, C, Assembly, C++

~~~
yajoe
I haven't seen a comment espousing the differences between languages since my
early days on /.

It's refreshing to see such passion, but I feel compelled to offer some
advice: languages are just "tools." No one tool is better than another for all
situations. JS seems like a reasonable place to start new programmers. Like
anything in software, it has its tradeoffs. Some thoughts:

* While the new programmer won't learn about call stacks or different parts of memory (considered essential when I learned to code), the programmer will learn to solve problems using control structures, method calls, recursion, and iteration. These are fundamental skills I see re-used in almost every language. Are there other awesome skills like functional programming I wish they would learn? Sure, but you have to start somewhere, and I support starting at if-else-then logic.

* Writing JavaScript is easy. No command line. No installing software. No compiling. No IDE. Just open your Web Console in Firefox or JavaScript Console in Chrome. Seriously, if you are teaching the masses on the internet, what better way than use the very tool they used to view your website?

* Writing JavaScript is in fashion. From Node.JS to last week's Tower.JS, JQuery, JSON, or the "new" HTML5 rage: JavaScript is popular. What better way to be relevant than teach what the industry is using? I support teaching popular things to introduce people to our industry.

[edited: /. not ./ derp!]

~~~
cmubruin
agreed!

------
elangoc
I'll go out on a limb to disagree with most of the comments here and say that
I think JS seems like it could be very effective. The Stanford CS101 course
page has already implemented decently well:
<http://www.stanford.edu/class/cs101/>

The language you learn doesn't have to be the language you end up using, or
using to learn CS. It just has to get you off the ground.

So many people get turned off from a subject when they "don't get it" at
first, so really, the challenge is providing the least painful intro to
programming. Personally, my first languages were Logo and Pascal, and since I
almost wrote off programming before Pascal as being too hard, I'm glad I saw
C++/Java only afterwards.

One thing that enamors me about the JS approach is that it reminds me a little
of Logo -- not only are the results are very immediate, but the visual output
gives us a constant second avenue of insight into what we're doing. I'm sure
many have seen Bret Victor's talk "Inventing on Principle"
(<http://vimeo.com/36579366>), and he underscores the benefits of direct
feedback to what we're doing. I have a friend taking CS10 at Berkeley this
semester, and the Scratch-based environment also seems equally cool.

That being said, I don't use JS much (haven't really touched in it 10 years),
but I believe it when people say it's (still) horribly irregular. In that
regard, it might be on par with some other scripting languages (e.g., Ruby).
So the distinction to be made here is that JS might be easy, but (as we can
see) not simple.

As people who program seriously, we need simplicity in a language in order to
build up large apps that we can easily reason about and don't bite us in every
corner. (Note: simplicity in a language doesn't necessarily mean it's going to
be easy at first.) But I wonder if we've been so used to programming that we
forget how it can be hard to learn at first, and we're just ruling out the
easy approach, which would exclude just what some newbies need.

~~~
tikhonj
Simplicity in a language is great.

JavaScript is actually a _very_ simple language modulo a small set of
irregularities. Most of these irregularities go away with "use strict", which
is basically the modern version of JavaScript anyhow. (And even more
improvements are in the pipeline with future versions, which you are free to
use for projects outside the browser!)

While there _are_ several reasons why I would not choose JavaScript first for
"serious" programming (although it's pretty high on the list), these reasons
are shared by most of the other popular languages like Python, Java and C++.
(I also think all three of these languages are more complex than JavaScript.)

If people who programmed "seriously" _actually_ cared about simplicity and
reasoning about code, we'd see much more Haskell in the wild. But instead we
see the three unfortunate languages I listed above: Python, Java and C++.
(Rounded out with mostly similar languages.)

~~~
elangoc
I totally agree. My statement about simple vs. easy is actually a weak attempt
at restating some of the principles that guided the design of Clojure (from
Rich Hickey's talk "Simple Made Easy":
<http://www.infoq.com/presentations/Simple-Made-Easy>) JS is approaching big
apps with Node.js, and Clojure is approaching browser JS with ClojureScript...
not sure how it will play out.

What are the current trends in language use? Are people moving away from
Python, Java, and C++? and if so, to what?

------
kung-fu-master
As CS teacher I'm agree with others that JS is terrible choice as first
language. Python is much better. Also Pascal is good option here. Even Java
better than JS.

What is their goal. It seems that John Resig only wants to teach his favorite
language/tool JS.

Main goal must be to teach fundamental CS concepts, programming basics,
algorithms and data structures. Language choice is must to be appropriate to
that goals.

He talks about teaching _prototypal inheritance_ , is he serious? For those
how have not any prior programming experience.

It seems, that he has no any prior pedagogical experience. Why that guy make
such decisions and why Khan academy can't hire more experienced CS teacher.

Yes, I know, he is great guy who wrotes jQuery, but pedagogy and JS
programming is two very different areas.

~~~
tikhonj
I think Java is a much worse choice--it's less elegant, more complicated and
requires treating more concepts as magic. (You can't even write "Hello, World"
without a class and a static method!)

I think Python is a worse choice because it's also more complicated and less
elegant than JavaScript (and it has its own share of pitfalls), but that seems
to be a minority opinion around here.

Prototypal inheritance is much simpler than classical inheritance--you don't
even have to introduce the idea of a class. I think it would be _easier_ to
teach prototypal inheritance rather than classical inheritance to people with
no programming experience.

The last two paragraphs of your post seem to mostly be an _ad hominem_.

~~~
kung-fu-master
Ok, maybe Java on some cases worse choice over JS. But Java has one
preeminence over JS. With Java we can teach more advantage level of software
construction. It's construction of medium/large systems. Programming in big.
Using classical OOP, interfaces and specification in achieving modularity and
decoupling.

JS was built for small scripts on web pages.

 _I think Python is a worse choice because it's also more complicated and less
elegant than JavaScript (and it has its own share of pitfalls), but that seems
to be a minority opinion around here._

You wrong, Python is much elegant than JS. Starting from syntax which was
derived from C/C++ like languages. With a lot of bugs and confusing behaviors
(some of was mentioned by Resig itself).

Code in Python is very clear and looks like pseudo-code. It's very easy to
read and very easy to start writing in it.

JS - specialized language for Web. Python - general purpose language.

 _Prototypal inheritance is much simpler than classical inheritance--you don't
even have to introduce the idea of a class. I think it would be easier to
teach prototypal inheritance rather than classical inheritance to people with
no programming experience._

There should be no inheritance for beginners. It's not even core CS concept.
No classes, no OOP in any kind of it (prototypal, classical).

I think with this approach we will get not CS professionals. We will get JS
script kiddies.

~~~
tikhonj
JavaScript--despite the syntax--largely takes semantics from Scheme and Self.

Python may _look_ more elegant, but there are some hidden issues--weird
variable scoping, dubious desugaring and crippled lambdas. (Also, the idea of
a function as value is easier to understand with the word "function" rather
than "lambda", something I would probably have changed in Scheme if using it
to teach beginners.)

Moreover, Python actually shares several of JavaScript's misfeatures like
weird loop scoping and the arbitrary statement/expression distinction. On top
of this, Python is far more hostile to functional programming than JavaScript.
(And this is _by design_!)

JavaScript is a much smaller language--Python has far more baked into the
language itself. This is why I find Python less elegant--thing like "in" have
no place in the language; they should be expressible as libraries. An elegant
language is small but can be extended by its users; Python's philosophy seems
to be the opposite. This is, again, where Scheme really shines.

I do not see why Java is a prerequisite to teaching "programming in big"--
nothing stops you from teaching modularity and loose coupling in JavaScript.
If anything it's _easier_ because of anonymous functions and libraries built
around passing functions around. (Java does have a static type system, which
is an advantage, but it's a pretty bad type system.)

Also, you seem to be perpetuating the same common myths about JavaScript--it
is as much a general purpose language as any and not particularly specialized
for small programs or the web. It's certainly as general purpose as Python
except perhaps a little lacking in some libraries. And with the advent of
Node, it's quickly getting all the libraries it needs.

------
cmubruin
I actually think that this is an interesting way to get people into
programming. I don't think Javascript is sufficient for many applications, but
it does serve a great purpose.

A lot of youth in the United States today aren't flocking to programming. We
need more. And yet it's strange because programming as an industry is what
afford young people the most opportunities. When was the last time you saw a
major non programming company have core contributors < 30 years old? < 25
years old?

JS as a language, TextPad as an editor, and a Browser as a runtime environment
is a far less intimidating barrier for students. People can see the results in
a medium that's familiar to them (a browser). It's also free and readily
available. No installs, no environment paths. nothing to discourage them. In
conjuction with HTML, they can see how JS/programming changes what they're
viewing. It will help bridge a lot of people's thoughts into "oh, wow, I can
actually do this and it has a tangible effect". When growing up I was
wondering how the hell a printout to a console would have any benefit to me.
Yet, that's how I was taught (in C, C++)

It's also been difficult recently to find frontend engineers. Colleges don't
train for this - it's all algorithms and abstract concepts that are great for
backend developers. That's why there are so many more backend engineers out
there than front end engineers. The FE side is under represented.

There are some arguments that this is a terrible first language because it's
not as rigid as the others. But honestly if you can't learn a language and
then apply the concepts and learn new ones to pick up new languages, you
probably shouldn't be tackling those tougher languages in the first place.

With HTML5 apps coming down the pipeline, people WILL need to know JS and we
as a technical industry will need to accept that they too are part of the
product/output of science/tech/web/mobile. Some people won't be diving in more
beyond that, but if they do, they at least have a foundation to build off of
as they get into more robust languages.

JS gets people in the door, and it's not going to preclude others from picking
up other first languages. It's a solid step for bringing more people into the
fold. It's not going to be the best for theory, but there are places and time
for that.

------
TeeWEE
Most. Stupid. Idea. Ever.

JavaScript is a language that misses a lot of important CS and the most
important of all is language build in modules.

Apart from that you should start with either a fully functional language or a
fully imperative OO language. These are theoratical distinct language classes.
And JavaScript is in the middle, you will confuse people.

At my university they started with Java.. also not the best choice. However
OOP is very important and just neglecting that initially is not a good idea.

From a theoretical point of view, javascript is not the best language to start
with. In fact as a language, its quite inferior to other function-imperative
language such as Python.

~~~
dpearson
I would disagree in this case. The mere fact that a JS engine is present in
any browser alone makes it compelling for those that have never programmed
before. There really is no setup, and the OS becomes (to a degree) irrelevant.
Further, javascript is an easy language to prototype in, and, at the basic
level, easy enough to teach and write.

~~~
judofyr
> There really is no setup

Except for creating an HTML-file and understanding how all that works.

> and the OS becomes (to a degree) irrelevant.

This is pretty much true for any language as long as you don't use platform-
specific features (fork).

> Further, javascript is an easy language to prototype in, and, at the basic
> level, easy enough to teach and write.

"Easy language to prototype in"? Both Python and Ruby are equally "easy", but
comes with even more batteries included. They also have a consistent object
model, as opposed to JavaScript's prototype-inheritance-is-cool-but-let's-mix-
in-constructors-from-classical-OOP. There's pretty much nothing like
JavaScript's prototypes in any other languages (Self/Io works quite
differently), and I don't really see any gain in teaching that to students
early on.

~~~
benihana
>Except for creating an HTML-file and understanding how all that works.

Using chrome? Hit [ctrl+shift+j|cmd+option+j] and you can write JavaScript
without any HTML necessary. Other browsers have similar consoles that need no
HTML to write JavaScript.

~~~
judofyr
Right. Let's teach programming in an environment that we _never_ use to create
full projects.

REPLs are fine to experiment with, but it's important to learn how you would
write "real" code. Dumbing down this essential concept is just silly.

~~~
simonw
Completely disagree - I write most of my production code in a REPL (either
JavaScript or Python), and only save it to a file once I know it's going to
work.

~~~
judofyr
I'm not against using REPL, but it's not viable to solely write in REPLs,
therefore we need to teach "how to run things in files" and then we're back at
crappy HTML-files.

~~~
syaz1
I don't see anybody saying one need to use REPLs only. What's nice with JS is
you have the option to open browser's JS console and try stuff there. You
don't _need_ to. But you _can_.

All modern browsers has JS console. That's dev environment setup freely for
you. And if you use FF, enhancing that env with Firebug is just a few clicks
away. WIth the rise of web apps nowadays, this is actually a very good move.

------
egiva
If the goal is to learn JavaScript as a first language, maybe it's better to
first learn it on Codecademy. Otherwise I really use Khan Academy for
everything. Also, JS is not a good first language for anyone. Never.

------
oscilloscope
Eloquent JavaScript is a great introductory programming text. You should
consider using it in a course. It's available under the Creative Commons
Attribution license:

<http://eloquentjavascript.net/>

------
hello_moto
Somehow I find that teaching QBasic for a person who has zero programming
language might be better than any other programming languages with Python as
the other candidate.

------
ejenkinsiii
yes, Khan going in the direction of programming languages seems abstract I've
been waiting for him to take the math video's and organize them in groups of
specific studies say for instance all math related to algorithmic studies,
specific engineering studies grouped all together like a course this seems
like it would be productive to the user instead it seems as though he's
beginning to jump on what's popular and add it to the site

~~~
hkolek
I agree. Their exercise framework can really use much improvement and there
are a ton of subjects that don't even have any exercises yet. I would like
them to concentrate on math and physics for now and work on really making
awesome content and exercises. They should leave the CS and programming stuff
for Coursera, Udacity etc. and focus on what they are good at (which
programming is not imho).

------
halayli
I'd use a language that at least got the very basics right (ex: ===, ==,
etc..) to lessen the confusion for new comers.

------
bobbles
Would it be possible to build a course around <http://www.openwebdevice.com/>
? (I assume that a lot of the knowledge would overlap)

------
muyuu
Is the canvas editor/exercise generator available somewhere as a package? I
saw the github code but couldn't find out how that was supposed to run in a
portable environment.

------
evanmoran
No CoffeeScript? =)

~~~
oscilloscope
I'm working on a CoffeeScript learning environment:

<http://fleetinbeing.net/beans/>

Still needs a decent JSON viewer before I start on the tutorials. It's a
problem that once code is evaluated, it turns into Javascript. JS2Coffee isn't
a satisfactory solution. I suspect teaching some Javascript, especially stuff
from Crockford's The Good Parts, will be necessary.

The advantage of course is it can be compiled and run natively in a browser.
The syntax is simpler, but there are corner cases. Though plain javascript
also has corner cases CoffeeScript doesn't have, and js syntax is more
intimidating.

------
fady
awesome. looking forward to this, which is coming from someone without any
formal education on programming. it will be good to see the difference between
understanding the principles via video, vs reading it in a book.

