For the interested (and with the caveat that I definitely would not suggest it for the Khan Academy's purposes), CoffeeScript does try to address all of the issues that John raises in his post.
Type Coercion: There is no `==` in CoffeeScript. You usually write `if x is y` in order to be particularly clear, but if you're in the mode of most other scripting languages, and you write `if x == y`, it will compile to `if (x === y) {` in JavaScript.
John's note about `x == null` being the only useful application of double equals is quite true, and something that CoffeeScript provides in the existential operator: `if x?`
Falsy Values: The existential operator helps you ask the question "Does this value exist?" (Is this value not either null of undefined?) ... which covers many of the use cases for having saner falsy values in JavaScript. For example, instead of JS' `if (string) {` ... where the string may be the empty string, you have `if string?`
Function Declarations: JavaScript having function declarations, function expressions, and named function expressions as three functionally different things is indeed a wart on the language. Especially so because JavaScript having a single type of function is one of the beautiful aspects that shines in comparison to languages like Ruby, where you have methods, blocks, procs, lamdas, and unbound methods -- all of which behave in slightly different ways. CoffeeScript only provides JS's function expressions.
Block Scope: This is a tricky one, because unfortunately it can't be emulated in a performant way in JavaScript. So all that CoffeeScript can provide is the "do" keyword, which immediately invokes the following function, forwarding arguments. So, if a regular "for" loop looks like this:
for item, index in list
...
A faux-block-scoped "for" loop would look like this:
I don't understand the (anti) hype about type coercion and the '==' operator. I get a faintly cargo-culty vibe from people when they talk about '===' vs '==', since the examples are usually very strange things that I never see in production. I'm not an expert in JavaScript but I've written a fair amount and a couple largish programs and I've never been bitten by a type-coercion bug involving '=='.
The weird subtle bugs I see are usually associated with me using "for (i in a)" for arrays instead of the more ugly C style for loop, which results in "i" being a string (which usually doesn't matter except when using "+" which is sometimes addition and sometime string concatenation).
So, is '==' really that bad? Has anyone seen (otherwise) well-written production code fail because of '==' vs '==='?
CoffeeScript is a subset of JavaScript with bindings to an alternate syntax (CoffeeScript). John's suggestion is an enforced subset of JavaScript, with the advantage that (some) JavaScript in the wild is understandable; error messages are in terms of the source language (very helpful, more so for beginners); and yields a skill with greater marketability (so far).
Why not use the same subset as CoffeeScript? In some cases, this simply forbids some constructs; in other cases it allows a construct, but only in certain contexts.
A mathematically precise but implementation-unfriendly definition is: only allow the subset of JavaScript that is the compilation of some CoffeeScript program.
These are all reasons why I've adopted CoffeeScript over JS. Sure, you can accomplish the same exact things in JS, but they are far more natural with CS and with far less typing. Less typing is less chance for mistakes and bugs and makes an easier learning experience.
One other line item is the encapsulation of classes in CS. Doing that in CS is natural and easy to explain to a first year programmer. Accomplishing the same thing in JS is far more boilerplate and much harder to explain why you have to fight the language to accomplish something as simple as a class.
Sure, you probably shouldn't learn CS without at least a general understanding of JS, but I definitely think that CS is the next logical step for the second semester.
As matter of fact, while I was reading the post the first that came to my mind was how much the recommendations reminded me of the CoffeeScript introductory page...
Block Scope: This is a tricky one, because unfortunately it can't be emulated in a performant way in JavaScript.
This is not true. ClojureScript does this and it's plenty efficient. What you lose is mutability of the loop local from inside a closed over function. Given how many people get burned by the JavaScript behavior clearly block scope is expected. I doubt anyone would miss the dubious ability to mutate a loop local via callback. Certainly not as much as I miss control over scope & names in CoffeeScript.
What, no disclaimer that you are actually the creator of coffeescript?? Your comment seems a bit biased to me. But I'd expect nothing less from a coffeescripter.
So you think it's better for someone who has no experience coding to have to understand why they would write some code one way, then have to "transpile" to something else to get it to run? Then if something goes wrong they have to figure out how to fix it in two languages? This doesn't sound like something I would recommend for a beginner, or someone experienced for that matter.
Whenever I see a post about what to use as a first language I always think about how I learned, and am learning, how to program. Warning: long-ish story/rant ahead.
My first class in high school was the basic Java 101. The teacher did not know anything more than how to draw UML diagrams and tell us to use for loops. He had been teaching the class for years and had no industry experience. I imagine 10 years ago he figured out all the questions he was going to ask and learned just enough to explain the really difficult ones. He was not a zen master LISP programmer who had glided down from the plane of Forms to enlighten us.
But I started to learn programming because of him. He knew what he knew and he had his presentation down. I didn't know how to program so anything was better than what I was going with. He explained terms and ideas in the most stereotypical of ways. But they made sense. In a way, he passed off his framework of knowledge to those who cared to take it. It was incredibly mind expanding at the time.
And so I had this little ball of specific domain knowledge. I wanted to be able to do cool stuff though on my website though. Java wasn't quite there yet, couldn't do all the things I wanted it to do. So I picked up Javascript from W3 schools online. It was terrible, awful Javascript that I have purposefully forgotten. But I could make my pages interactive, I could impress my friends. My little ball of know how was growing and expanding. I kept at it and started seeing how Java "sucked" and why Javascript was the One True Language. New ideas like functions as variables, easy to run scripts, interactive webpages, they all got added on and replaced old less useful ideas from Java.
Pretty soon after that I started actively learning Mathematica in college. The whole IDE is just lisp with some mathematical lipstick, but I didn't know that at the time. I started thinking of how to solve problems with lists, how to use IDE's, and reading and writing to files so I wouldn't have to redo everything each time. I had programs that wouldn't run in less than a second which made me really aware of what I was writing and how to optimize things.
And the story just keeps going and going on like that. Common lisp with Emacs last winter because of PG. More Mathematica and jQuery during last spring and summer because of an Internship. Node, Haskell, Clojure, Python during this past fall for enlightenment. And now R and, maybe, Ruby/Rails during the winter because I have ideas I want to make happen. I'm by no means a professional, but I know enough to shoot the shit with the CS majors and randomly drop into tech meetups (What up Cinci.rb!)
All that sprung from a high school class taught by a standard teacher on a shitty language that I don't ever want to touch again. And so when people talk about first languages and why X will be an absolutely horrible language to use to learn, I zone out. Every language is going to be a horrible first language. All of them. I don't care what arguments you make about js gotchas or Python's batteries included or why scheme is more beautifuller than common. If you don't know how to program, learning how to program is going to suck. Period. Maybe learning C++ first isn't the hottest idea, but at some point you have to grit your teeth and go "Programming is hard."
So I applaud Resig's and Khan Academy's use of javascript. Not because I love javascript, but because I know they are going to doing an amazing job presenting the tiny balls of programming knowledge to kids across the world. They could have picked most any mainstream language they want to present these ideas with and I would still be excited by their ideas. All that matters is how they plant the seeds. If they can stir up a kid's desire enough to get over the "ARRAYS SUCK. FOR LOOPS SUCK. WHY WON'T MY PROGRAM COMPILEEEE." and learn the next language or build the next project, then they have done an amazing job and good for the world.
tl;dr Programming is hard, every language has it's own use, waffling about the choice of languages isn't going to teach you what you need to know any faster.
One might say the same about the English language, yet it is taught in classrooms all across the United States, despite the fact that the U.S. has no codified national language. English is the de facto national language, but nothing more.
So why Javascript as a first language? Probably the best argument is that it has the widest reach of any programming language in use today because Javascript will run in any web browser on any platform. It is the closest thing to a universal programming language you'll find today.
I suspect Mr. Resig is familiar with the potential gotchas, and maybe even has his reasons for still believing it's still worthwhile.
For my own part, as someone who regularly taught high school seniors (and other non-programmers) various programming languages (Pascal, Perl, Prolog, JavaScript, and Java) over a good chunk of the 1990s, I have to say that JavaScript worked out pretty well, possibly even the best of the bunch depending on what your goals were.
Prolog had some real strengths. The combination of accessibility for some simple applications with the power and conceptual depth of the logic paradigm tended to put more or less smart people with no previous experience on the same footing with those with some experience.
But JavaScript seemed to be the best of the bunch in terms of balancing accessibility, speed from which students could get to doing something with everyday practical use, and available depth.
And despite the fact that those of us who were teaching were just learning and coming to grips with some of the "bad parts" ourselves (because how many people really knew JavaScript in the 1990s, right?), everybody got stuff done anyway.
Whatever, Javascript is the easiest language to get started on. No installing a complicated IDE. No configuring a server. Nothing is required except for a browser!
If anything, it's the best language for such purposes: getting started.
Every language has its gotchas. Even assignment operators are kind of a gotcha.
If you're coming from a basic math background, and have no programming experience, then the expression "a = 15; a = a + 1;" would be confusing in any mutable language, because assigning a value to a variable is not equivalent to stating the equality (identity) of both sides.
Also, as stated by John, JSlint will be used. That by itself avoid the big majority of JS' gotchas. And IMO, C++ has way more gotchas than Javascript and that doesn't stop universities to teach it as first language.
In fact, I think the first language is not just about giving a strong foundation but also give students the chance to find a good internship. So, with that logic, even though I enjoy hacking with Scheme, I'd feel bad to teach that to students who will try to find an internship and writing on their resumes "Scheme" while other universities students would have "C++/Java". And, please, before your argue that a language can be learned or something else, have in mind how companies recruit and parse resumes.. they often just search for a keyword. Now, one might say that you don't want to work for a company who does that, but then, you have to start somewhere in your first internship.
Thus, I like JavaScript as a first language; not because it's the easiest to learn but because I believe it gives a strong foundation but also gives students the ability to find a good internship.
I have to agree. BASIC is a far better option. It will obviously never be used for anything, but it will teach the student basic concepts like output, input, variables, etc.
These are not simple concepts for somebody starting from zero!
That's just logical and obvious, since "+" is both numerical addition, and string concatenation, but "-" is only numerical subtraction, and the '5' starts out as a string.
Every language has 'gotchas'. Doesn't really matter which you pick to learn first at all. The more important thing is that you don't give up. possibly there are languages that just make people want to give up, but I'd say perhaps they're not motivated enough to learn if that's the case.
I started out on BASIC, and after a while I decided it was a piece of shit language and learnt assembly. But it taught me programming which is what I wanted to learn. I'm really glad I learnt BASIC first... essentially I learnt to swim really fast through syrup, and then switched to swimming in water.
The good thing about javascript as a first language is that people can be programming in it immediately, in their browser. They have a built in REPL to help them, as well as a debugger, profiler, etc. They have numerous docs to look at, and if they go to any website they can check the source to see how it works. That's a big win.
I'm a fairly experienced programmer and JS still drives me up the wall. The implicit casting and inconsistent operator overloads have led to many unhappy visits to Stack Overflow to see just WTF my browser is doing. I can't imagine the experience being any better for newbie programmers! Even simple things, like bitwise operators, are basically broken unless you take care to ensure that your variables are coerced to whole numbers, because all numerics are f%!#^&ing floating point numbers...
Given that the language is such a mess, I think it would induce a new programmer to compartmentalize their JS learnings as a bunch of special case hacks instead of discovering broad language principles that are applied consistently across the language.
I have argued JS as an intro language for years. My main argument has been not based on language features which I feel are unimportant in forming a young programmers mind but rather in the complete lack of barriers to getting started.
Take for instance python( my personal language). At a minimum you need python installed on the computer. Then you need to deal with issues such as the PATH and PYTHON_PATH. Also you have to understand package naming and import scheme.
With JS you only need a .html text file on the desktop.
Write code, save, double click, results. It is something that anyone who has even seen a computer can understand.
Particularly if the student has not had much experience in computers in general, things like paths, imports, file system knowledge and command line interfaces can be a barrier to learning code. You will eventually need to learn all of the things above to be a programmer but why bore a child or teenager with the details of a file system or command line when you could be showing them how to code animations on a web page.
I will admit, that struggling with run time environment, compilers and class path issues made me into better engineer sooner, but I already had a passion for what I was doing.
Yeah, JavaScript will break their impressionable young minds. But you know what? Programming in general will break their minds. Programming is fucked up from any perspective. If they learn a good language first, they will go crazy trying to figure out why nobody is using it. Might as well teach them a language that lets them get stuff done in the real world, while preparing them for the ugliness ahead. They can learn the good language later.
I support using JavaScript as a first language. If for nothing else there are millions of code snippets just a short "right click -> view source" away. Granted these may not be the most ideal examples, but it enables tinkering. One thing that always frustrated me about the "easy" languages to learn (Python, Ruby, etc) is you still have to figure out how to download something and then the first programs just write out text to a console window. It's hard to see at first how learning one of the "easy" languages translates into building cool stuff.
Having access to such a vast array of samples, plus something like Khan Acadamy teaching the "right way" is just awesome to me.
Reading this I reminded of the saying "when you have a hammer everything looks like a nail". It's not surprising to see John Resig leaning towards using Javascript. There is a lot of research into teaching introductory programming. It would be nice to see some of that referenced in making the decision. You know, base it at least in part on science rather than just opinion.
I am so looking forward to a huge army of newly-trained programmers who view prototype-based inheritance as the default and classical inheritance as weird.
Similarly, I look forward to a whole set of various modules and libraries to graft prototype-based inheritance onto existing languages like Ruby...
I think it'd be more apt to choose something like Racket. It has all the desirable characteristics the author finds attractive in Javascript. It is an integrated environment and includes libraries and extensions for teaching basic programming. Unlike Javascript it isn't married to the browser (and by extension, the DOM) and doesn't suffer from a variety of syntactical discrepancies. It even comes with a free book for teaching the fundamentals of computer programming and computation.
Update: All of the desire-able characteristics except for being a resume-search keyword with a high hit frequency. IMO, learning how to program and getting a job are orthogonal.
tl;dr - they picked JS due to its "ubiquity, desirability in the larger workforce, lack of prior installation requirements, and ability to create something that's easy to share with friends"
I find that explanation disturbing. Why not start from a language that teaches the basics of the common programming paradigms, such as OOP (Java) or FP (Scheme)?
You may have a different perspective, but if I wanted to teach OOP to new programmers, Java would be the last language I would consider, not the first. It’s a fine language in a vocational setting where the objective is to graduate people for employment as Java programmers, of course.
Scheme is elegant and small, and a traditional choice for teaching programming where functions are first-class objects. If you consider Scheme appropriate for FP, my guess is that you’d also consider SmallTalk appropriate for teaching OOP.
> Why not start from a language that teaches the basics of the common programming paradigms, such as OOP (Java) or FP (Scheme)?
Because that stuff is boring and it drives away a bunch of people who might really get in to programming if there wasn't a huge gap between "just starting" and "doing anything remotely cool".
I for one would not have become a developer if my first experience with programming was a typical "CS101: Let's spend 3 months learning about loops" class, which unfortunately is many students first introduction. This class alone probably drives away half of the people who were interested in programming enough to take the class in the first place, which I find disturbing.
I spent a bunch of my free time as a kid making (really bad) web pages, (really bad) Javascript, and (really bad) PHP. Did I understand OOP, or how/why it's different than FP? Heck no. It wasn't until years later that I even took a programming course. But by the time I was ready to learn solid programming fundamentals, I'd already been bitten by the programming bug.
If I had to guess, I'd say this class is more about getting people interested in programming than it is intended to teach everything you Should Know. IMO, that's what a beginner course on any heavy material should be anyway.
As every PHP programmer knows today, and all of us Applesoft BASIC and Apple Pascal programmers knew when we were beginners, OOP and FP are unnecessary stumbling blocks between a new programmer and a very large class of fun computer programs.
for new programmers, the entry barrier for those languages is significantly greater than javascript. people don't quit learning programming because they're not learning OOP- they quit because it's inaccessible.
Ability to create something you can share (or that you can other wise readily "put to use") is important. If you lose your audience because they don't get satisfaction early enough, well, they are gone. While programmers certainly want to weigh in on the issue (obviously), the experience of teachers and psychologists would suggest that keeping the carrot close is immensely valuable to getting someone to learn something.
I would prefer to err on the side of not using OOP at all for the first year or so. The problems it solves have better solutions if you're not using a terrible language. They also seem extremely contrived when you introduce them long before the students have any chance of producing a program with those problems, so the students frequently end up using OOP all the time when it's not really called for.
I definitely agree with your point about stack traces - I've used var x = function(){} for some projects, but have found in practice that named functions are very much worthwhile when dealing with stack traces?
What's the benefit of var x = function x(){}? Is it just illustration that functions can be assigned to variables?
I have to disagree. Part of the reason is that it teaches the concept of anonymous functions.
The main reason, though, is the anonymous function case makes it more apparent that the function is an object.
Separating the RHS from the LHS is significant. The right side creates the object, the left side binds it to the reference. Much like `var a = 3`.
It is the assignment that makes it interesting for people that I teach JavaScript. Consider the following, can you do that in a less function-oriented language like Java easily?
var getData = function () {};
var mygetdata = getdata;
getData("foo")
mygetData("foo")
There is actual research on how to teach kids programming and computer science concepts. http://csunplugged.org/ doesn't use any software at all to teach concepts like binary numbers, sorting, etc.
Before I even read the article, I was pretty sure that with a title like that there is going to be lots of debate from the CS people. They do raise some good points, but here's my 2 cents.
Besides a little bit of VB in highschool, JavaScript was my first language. I mainly learned through two books: "The Good Parts" which was a nice overview, and "Object-Oriented JavaScript" a really underrated book that covered every little piece of the language, even those weird parts like block scoping and falsy types.
Having never learned anything about classes or inheritance, prototypal inheritance was kinda hard to grasp, but I eventually found it pretty amazing. I think a loosely typed language is much better to learn on too. That way you can learn the big pieces of the language then later get into the little things like typing. That's just my experience, but I'm really glad JS was my first language.
I want to take this further still. Most JavaScript programmers already use a subset of the language and I believe that there is quite a broad union of those subsets that should resonate with the majority of us. Excluding certain parts of the language will lead to more robust code that is easier to reason about (and more fun to write), I claim. My attempt to formalize it is called "restrict mode for JavaScript" http://restrictmode.org and I laid my case here: http://blog.lassus.se/2011/03/case-for-restrict-mode.html . Would be curious to hear other thoughts about it.
One thing that I have not seen covered that is worth mentioning, is that JavaScript for the most part embraces an event based development model. While it is not unique to JavaScript it certainly is heavily reinforced by JavaScript and JavaScript developers. In other languages it can be fairly underrepresented, that being said, it is worth learning JavaScript due to the fact that it helps developers think of execution as events. One can go their whole life in other language and not deal with events, with JavaScript you will be hard pressed to get to intermediate tutorials without fairly good coverage of events and event syndication.
If you want to teach computer science to people then a good first language for them to learn is C, because it will help them think about and understand what the computer is actually doing.
That's an argument for learning C, but not for learning C as a first language. Studying assembler or chip design or even particle physics will also help you understand what the computer is 'actually doing', but it doesn't mean that's the best place to start learning how to program.
On a similar note, I've been in the process of creating a JavaScript library[0] that is strongly inspired by _why's Shoes. My intent for doing this was to create a DSL where one can whip up webapps very quickly. But I'm also now looking into essentially recreating Hackety Hack on the web, and maybe having a simple way for very young people to get a taste of programming. Sadly JS isn't as DSL friendly as Ruby.
I know for me the way I learnt programming made me quite flexible and happy.
Working the entire scale from functional to OO languages gave me a really good perspective for anything I face.
I've learnt all the web stuff I use today completely on my own, but I use the foundation I learnt below. The "classic" academic programming languages I've learnt happened in this order.
Basic -> VB -> Pascal (High school/first year Uni) --> C --> C++ --> Java
Too much code out there rarely exists entirely on the OO or functional end and projects are often heading towards one or the other.
Once I had traversed this, I was easily able to pick up .NET, whether any one of the .NET languages was OO or functionally based (Foxpro, or whatever). Javascript was interesting because it extended from Java for me.
I really do feel that programming needs to be learnt at the mathematical/computational level of functions for clear process/analytics and then learn the benefits of using functions in an OO world.
I'm a full-time javascript developer and entrepreneur myself, but I'm wondering why you don't consider Scheme instead, basing the course on the How to Design Programs v2 curriculum?
The people behind that book have spent a lot of time thinking about how you teach programs to people.
More importantly, they focus on problem decomposition and concepts that provide a great foundation for growing.
The reasons I can see for using Javascript first is because everyone has a runtime available at their fingertips (M. Haverbeke's approach of including the console was great.) and because people can immediately see the utility of the language to real world needs.
But does Javascript provide the best foundation for future concepts? Does it teach good habits both mental and in practice?
[+] [-] jashkenas|14 years ago|reply
Type Coercion: There is no `==` in CoffeeScript. You usually write `if x is y` in order to be particularly clear, but if you're in the mode of most other scripting languages, and you write `if x == y`, it will compile to `if (x === y) {` in JavaScript.
John's note about `x == null` being the only useful application of double equals is quite true, and something that CoffeeScript provides in the existential operator: `if x?`
Falsy Values: The existential operator helps you ask the question "Does this value exist?" (Is this value not either null of undefined?) ... which covers many of the use cases for having saner falsy values in JavaScript. For example, instead of JS' `if (string) {` ... where the string may be the empty string, you have `if string?`
Function Declarations: JavaScript having function declarations, function expressions, and named function expressions as three functionally different things is indeed a wart on the language. Especially so because JavaScript having a single type of function is one of the beautiful aspects that shines in comparison to languages like Ruby, where you have methods, blocks, procs, lamdas, and unbound methods -- all of which behave in slightly different ways. CoffeeScript only provides JS's function expressions.
Block Scope: This is a tricky one, because unfortunately it can't be emulated in a performant way in JavaScript. So all that CoffeeScript can provide is the "do" keyword, which immediately invokes the following function, forwarding arguments. So, if a regular "for" loop looks like this:
A faux-block-scoped "for" loop would look like this:[+] [-] __david__|14 years ago|reply
The weird subtle bugs I see are usually associated with me using "for (i in a)" for arrays instead of the more ugly C style for loop, which results in "i" being a string (which usually doesn't matter except when using "+" which is sometimes addition and sometime string concatenation).
So, is '==' really that bad? Has anyone seen (otherwise) well-written production code fail because of '==' vs '==='?
[+] [-] 6ren|14 years ago|reply
Why not use the same subset as CoffeeScript? In some cases, this simply forbids some constructs; in other cases it allows a construct, but only in certain contexts.
A mathematically precise but implementation-unfriendly definition is: only allow the subset of JavaScript that is the compilation of some CoffeeScript program.
[+] [-] latchkey|14 years ago|reply
One other line item is the encapsulation of classes in CS. Doing that in CS is natural and easy to explain to a first year programmer. Accomplishing the same thing in JS is far more boilerplate and much harder to explain why you have to fight the language to accomplish something as simple as a class.
Sure, you probably shouldn't learn CS without at least a general understanding of JS, but I definitely think that CS is the next logical step for the second semester.
[+] [-] danmaz74|14 years ago|reply
[+] [-] swannodette|14 years ago|reply
This is not true. ClojureScript does this and it's plenty efficient. What you lose is mutability of the loop local from inside a closed over function. Given how many people get burned by the JavaScript behavior clearly block scope is expected. I doubt anyone would miss the dubious ability to mutate a loop local via callback. Certainly not as much as I miss control over scope & names in CoffeeScript.
[+] [-] limeblack|14 years ago|reply
http://img856.imageshack.us/img856/306/javascriptinasimplewa...
[+] [-] unknown|14 years ago|reply
[deleted]
[+] [-] unknown|14 years ago|reply
[deleted]
[+] [-] gnaritas|14 years ago|reply
[+] [-] unknown|14 years ago|reply
[deleted]
[+] [-] leptons|14 years ago|reply
So you think it's better for someone who has no experience coding to have to understand why they would write some code one way, then have to "transpile" to something else to get it to run? Then if something goes wrong they have to figure out how to fix it in two languages? This doesn't sound like something I would recommend for a beginner, or someone experienced for that matter.
[+] [-] absconditus|14 years ago|reply
http://stackoverflow.com/questions/1995113/strangest-languag...
[+] [-] zackzackzack|14 years ago|reply
My first class in high school was the basic Java 101. The teacher did not know anything more than how to draw UML diagrams and tell us to use for loops. He had been teaching the class for years and had no industry experience. I imagine 10 years ago he figured out all the questions he was going to ask and learned just enough to explain the really difficult ones. He was not a zen master LISP programmer who had glided down from the plane of Forms to enlighten us.
But I started to learn programming because of him. He knew what he knew and he had his presentation down. I didn't know how to program so anything was better than what I was going with. He explained terms and ideas in the most stereotypical of ways. But they made sense. In a way, he passed off his framework of knowledge to those who cared to take it. It was incredibly mind expanding at the time.
And so I had this little ball of specific domain knowledge. I wanted to be able to do cool stuff though on my website though. Java wasn't quite there yet, couldn't do all the things I wanted it to do. So I picked up Javascript from W3 schools online. It was terrible, awful Javascript that I have purposefully forgotten. But I could make my pages interactive, I could impress my friends. My little ball of know how was growing and expanding. I kept at it and started seeing how Java "sucked" and why Javascript was the One True Language. New ideas like functions as variables, easy to run scripts, interactive webpages, they all got added on and replaced old less useful ideas from Java.
Pretty soon after that I started actively learning Mathematica in college. The whole IDE is just lisp with some mathematical lipstick, but I didn't know that at the time. I started thinking of how to solve problems with lists, how to use IDE's, and reading and writing to files so I wouldn't have to redo everything each time. I had programs that wouldn't run in less than a second which made me really aware of what I was writing and how to optimize things.
And the story just keeps going and going on like that. Common lisp with Emacs last winter because of PG. More Mathematica and jQuery during last spring and summer because of an Internship. Node, Haskell, Clojure, Python during this past fall for enlightenment. And now R and, maybe, Ruby/Rails during the winter because I have ideas I want to make happen. I'm by no means a professional, but I know enough to shoot the shit with the CS majors and randomly drop into tech meetups (What up Cinci.rb!)
All that sprung from a high school class taught by a standard teacher on a shitty language that I don't ever want to touch again. And so when people talk about first languages and why X will be an absolutely horrible language to use to learn, I zone out. Every language is going to be a horrible first language. All of them. I don't care what arguments you make about js gotchas or Python's batteries included or why scheme is more beautifuller than common. If you don't know how to program, learning how to program is going to suck. Period. Maybe learning C++ first isn't the hottest idea, but at some point you have to grit your teeth and go "Programming is hard."
So I applaud Resig's and Khan Academy's use of javascript. Not because I love javascript, but because I know they are going to doing an amazing job presenting the tiny balls of programming knowledge to kids across the world. They could have picked most any mainstream language they want to present these ideas with and I would still be excited by their ideas. All that matters is how they plant the seeds. If they can stir up a kid's desire enough to get over the "ARRAYS SUCK. FOR LOOPS SUCK. WHY WON'T MY PROGRAM COMPILEEEE." and learn the next language or build the next project, then they have done an amazing job and good for the world.
tl;dr Programming is hard, every language has it's own use, waffling about the choice of languages isn't going to teach you what you need to know any faster.
[+] [-] bradleyland|14 years ago|reply
So why Javascript as a first language? Probably the best argument is that it has the widest reach of any programming language in use today because Javascript will run in any web browser on any platform. It is the closest thing to a universal programming language you'll find today.
[+] [-] wwweston|14 years ago|reply
For my own part, as someone who regularly taught high school seniors (and other non-programmers) various programming languages (Pascal, Perl, Prolog, JavaScript, and Java) over a good chunk of the 1990s, I have to say that JavaScript worked out pretty well, possibly even the best of the bunch depending on what your goals were.
Prolog had some real strengths. The combination of accessibility for some simple applications with the power and conceptual depth of the logic paradigm tended to put more or less smart people with no previous experience on the same footing with those with some experience.
But JavaScript seemed to be the best of the bunch in terms of balancing accessibility, speed from which students could get to doing something with everyday practical use, and available depth.
And despite the fact that those of us who were teaching were just learning and coming to grips with some of the "bad parts" ourselves (because how many people really knew JavaScript in the 1990s, right?), everybody got stuff done anyway.
[+] [-] DrHankPym|14 years ago|reply
If anything, it's the best language for such purposes: getting started.
[+] [-] asktell|14 years ago|reply
If you're coming from a basic math background, and have no programming experience, then the expression "a = 15; a = a + 1;" would be confusing in any mutable language, because assigning a value to a variable is not equivalent to stating the equality (identity) of both sides.
[+] [-] phzbOx|14 years ago|reply
In fact, I think the first language is not just about giving a strong foundation but also give students the chance to find a good internship. So, with that logic, even though I enjoy hacking with Scheme, I'd feel bad to teach that to students who will try to find an internship and writing on their resumes "Scheme" while other universities students would have "C++/Java". And, please, before your argue that a language can be learned or something else, have in mind how companies recruit and parse resumes.. they often just search for a keyword. Now, one might say that you don't want to work for a company who does that, but then, you have to start somewhere in your first internship.
Thus, I like JavaScript as a first language; not because it's the easiest to learn but because I believe it gives a strong foundation but also gives students the ability to find a good internship.
[+] [-] maratd|14 years ago|reply
These are not simple concepts for somebody starting from zero!
[+] [-] bdfh42|14 years ago|reply
Also it is very applicable for many new programmers - an all round good choice.
[+] [-] maximusprime|14 years ago|reply
Every language has 'gotchas'. Doesn't really matter which you pick to learn first at all. The more important thing is that you don't give up. possibly there are languages that just make people want to give up, but I'd say perhaps they're not motivated enough to learn if that's the case.
I started out on BASIC, and after a while I decided it was a piece of shit language and learnt assembly. But it taught me programming which is what I wanted to learn. I'm really glad I learnt BASIC first... essentially I learnt to swim really fast through syrup, and then switched to swimming in water.
The good thing about javascript as a first language is that people can be programming in it immediately, in their browser. They have a built in REPL to help them, as well as a debugger, profiler, etc. They have numerous docs to look at, and if they go to any website they can check the source to see how it works. That's a big win.
[+] [-] laconian|14 years ago|reply
Given that the language is such a mess, I think it would induce a new programmer to compartmentalize their JS learnings as a bunch of special case hacks instead of discovering broad language principles that are applied consistently across the language.
[+] [-] IanMechura|14 years ago|reply
Take for instance python( my personal language). At a minimum you need python installed on the computer. Then you need to deal with issues such as the PATH and PYTHON_PATH. Also you have to understand package naming and import scheme.
With JS you only need a .html text file on the desktop.
Write code, save, double click, results. It is something that anyone who has even seen a computer can understand.
Particularly if the student has not had much experience in computers in general, things like paths, imports, file system knowledge and command line interfaces can be a barrier to learning code. You will eventually need to learn all of the things above to be a programmer but why bore a child or teenager with the details of a file system or command line when you could be showing them how to code animations on a web page.
I will admit, that struggling with run time environment, compilers and class path issues made me into better engineer sooner, but I already had a passion for what I was doing.
[+] [-] extension|14 years ago|reply
[+] [-] sirchristian|14 years ago|reply
Having access to such a vast array of samples, plus something like Khan Acadamy teaching the "right way" is just awesome to me.
[+] [-] noelwelsh|14 years ago|reply
[+] [-] angelbob|14 years ago|reply
Similarly, I look forward to a whole set of various modules and libraries to graft prototype-based inheritance onto existing languages like Ruby...
cackle
[+] [-] agentultra|14 years ago|reply
http://docs.racket-lang.org/quick/
Update: All of the desire-able characteristics except for being a resume-search keyword with a high hit frequency. IMO, learning how to program and getting a job are orthogonal.
[+] [-] yuvadam|14 years ago|reply
I find that explanation disturbing. Why not start from a language that teaches the basics of the common programming paradigms, such as OOP (Java) or FP (Scheme)?
[+] [-] raganwald|14 years ago|reply
Scheme is elegant and small, and a traditional choice for teaching programming where functions are first-class objects. If you consider Scheme appropriate for FP, my guess is that you’d also consider SmallTalk appropriate for teaching OOP.
[+] [-] tomg|14 years ago|reply
Because that stuff is boring and it drives away a bunch of people who might really get in to programming if there wasn't a huge gap between "just starting" and "doing anything remotely cool".
I for one would not have become a developer if my first experience with programming was a typical "CS101: Let's spend 3 months learning about loops" class, which unfortunately is many students first introduction. This class alone probably drives away half of the people who were interested in programming enough to take the class in the first place, which I find disturbing.
I spent a bunch of my free time as a kid making (really bad) web pages, (really bad) Javascript, and (really bad) PHP. Did I understand OOP, or how/why it's different than FP? Heck no. It wasn't until years later that I even took a programming course. But by the time I was ready to learn solid programming fundamentals, I'd already been bitten by the programming bug.
If I had to guess, I'd say this class is more about getting people interested in programming than it is intended to teach everything you Should Know. IMO, that's what a beginner course on any heavy material should be anyway.
[+] [-] mechanical_fish|14 years ago|reply
[+] [-] catshirt|14 years ago|reply
[+] [-] robbrown451|14 years ago|reply
[+] [-] anonymoushn|14 years ago|reply
[+] [-] njonsson|14 years ago|reply
[+] [-] apalmblad|14 years ago|reply
What's the benefit of var x = function x(){}? Is it just illustration that functions can be assigned to variables?
[+] [-] ludwigvan|14 years ago|reply
The main reason, though, is the anonymous function case makes it more apparent that the function is an object.
Separating the RHS from the LHS is significant. The right side creates the object, the left side binds it to the reference. Much like `var a = 3`.
It is the assignment that makes it interesting for people that I teach JavaScript. Consider the following, can you do that in a less function-oriented language like Java easily?
[+] [-] lowglow|14 years ago|reply
[+] [-] edtechdev|14 years ago|reply
But personally, for high schoolers, I would start with Scratch ( http://scratch.mit.edu - scratch 2 will work in the browser) and then perhaps Processing.js or a game development site/tool like http://html5.yoyogames.com/ http://www.scirra.com/construct2 http://www.playmycode.com/ http://pixieengine.com/
There is actual research on how to teach kids programming and computer science concepts. http://csunplugged.org/ doesn't use any software at all to teach concepts like binary numbers, sorting, etc.
[+] [-] firefoxman1|14 years ago|reply
Besides a little bit of VB in highschool, JavaScript was my first language. I mainly learned through two books: "The Good Parts" which was a nice overview, and "Object-Oriented JavaScript" a really underrated book that covered every little piece of the language, even those weird parts like block scoping and falsy types.
Having never learned anything about classes or inheritance, prototypal inheritance was kinda hard to grasp, but I eventually found it pretty amazing. I think a loosely typed language is much better to learn on too. That way you can learn the big pieces of the language then later get into the little things like typing. That's just my experience, but I'm really glad JS was my first language.
[+] [-] olov|14 years ago|reply
[+] [-] kls|14 years ago|reply
[+] [-] arctangent|14 years ago|reply
[+] [-] danenania|14 years ago|reply
[+] [-] city41|14 years ago|reply
[0] https://github.com/city41/Joeys
[+] [-] glenjamin|14 years ago|reply
I don't think it'll affect JS-as-a-first-language people.
[+] [-] j45|14 years ago|reply
I know for me the way I learnt programming made me quite flexible and happy.
Working the entire scale from functional to OO languages gave me a really good perspective for anything I face.
I've learnt all the web stuff I use today completely on my own, but I use the foundation I learnt below. The "classic" academic programming languages I've learnt happened in this order.
Basic -> VB -> Pascal (High school/first year Uni) --> C --> C++ --> Java
Too much code out there rarely exists entirely on the OO or functional end and projects are often heading towards one or the other.
Once I had traversed this, I was easily able to pick up .NET, whether any one of the .NET languages was OO or functionally based (Foxpro, or whatever). Javascript was interesting because it extended from Java for me.
I really do feel that programming needs to be learnt at the mathematical/computational level of functions for clear process/analytics and then learn the benefits of using functions in an OO world.
Be interested to hear what order others learnt
[+] [-] malandrew|14 years ago|reply
The people behind that book have spent a lot of time thinking about how you teach programs to people.
More importantly, they focus on problem decomposition and concepts that provide a great foundation for growing.
The reasons I can see for using Javascript first is because everyone has a runtime available at their fingertips (M. Haverbeke's approach of including the console was great.) and because people can immediately see the utility of the language to real world needs.
But does Javascript provide the best foundation for future concepts? Does it teach good habits both mental and in practice?
Ref: The Structure and Interpretation of the Computer Science Curriculum http://www.ccs.neu.edu/racket/pubs/jfp2004-fffk.pdf