Live data from Hacker News

John Resig: JavaScript as a First Language

ejohn.org

41–50 of 228 posts

Re: John Resig: JavaScript as a First Language

#41
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:

    for item, index in list
      do (item, index) ->
        ...

Re: John Resig: JavaScript as a First Language

#42

Earlier quoted context omitted.

Strict Equals Operator (===) does exactly what I expect and that is no funny coercion or guessing, two objects I'm evaluating have a 1 for 1 likeness, no more no less. How is that confusing?

NaN !== NaN Apart from that, I agree.

Sure but at least the spec is clear that NaN always returns false.

Re: John Resig: JavaScript as a First Language

#43

Javascript is an absolutely horrible language to use for such purposes. There are far too many gotchas. See the following for numerous examples: http://stackoverflow.com/questions/1995113/strangest-languag...

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.

Re: John Resig: JavaScript as a First Language

#44
post #4

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)?

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.

Let them quit. Many of us learned to program before the commercial Internet existed and at a time when desktop computers were not found in every home. If someone finds learning to programming to be "inaccessible" now then I rather that they not join our industry.

Re: John Resig: JavaScript as a First Language

#45

Earlier quoted context omitted.

Everyone already has a browser, which includes a profiler, debugger, REPL etc. Not everyone has a c compiler or JDK, or wants the hassle of having to set them up just to start learning.

I struggle with this mindset. It probably makes sense for Khan Academy, but this industry (software development) needs fewer people who refuse to learn anything unless all obstacles are removed and the information is spoon fed.

I find your statement to be amusing considering a lot of the anti-JS comments on this thread are about how unwieldy it is as a language. Of course, your critique and those complaints are two different things. You are criticizing that people are too coddled about having an accessible environment to program in. The complaints are that JS is too unfriendly and muddled, and so does not coddle beginners enough!

Re: John Resig: JavaScript as a First Language

#46

Javascript is an absolutely horrible language to use for such purposes. There are far too many gotchas. See the following for numerous examples: http://stackoverflow.com/questions/1995113/strangest-languag...

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.

Re: John Resig: JavaScript as a First Language

#47
All decent suggestions. I quibble with this, though:

  // Don't do this:
  function getData() { }
  // Do this instead:
  var getData = function() { };
The assignment is righteous, but by omitting the function’s name, you make stack traces more difficult to follow. Better this instead:

  var getData = function getData() { };

Re: John Resig: JavaScript as a First Language

#48

Earlier quoted context omitted.

You're looking at the wrong side of it. The subtraction does behave in a perfectly logical manner. The problem is that, given the the behavior of the subtraction operator, the addition operator's actions are illogical. Specifically, I'd argue it's perverse because it breaks commutativity: '5' + 3 - 3 != '5' - 3 + 3 The logical approach would be to only assume that '+' is a string concatenation if both operands are st…

That would be ridiculous because then what would 'hello' + 1 equal? Everyone would expect it to equal 'hello1'.

Except, not "everyone" would expect that.

I'd expect "hello" - 1 to return NaN, since you can't perform numerical subtraction on something that isn't a number. That's exactly what Javascript does.

In the same way, I'd expect "hello" + 1 to return Nan, since you can't perform string concatenation on something that isn't a string, and you can't perform numerical addition on something that isn't a number.

Edited for clarity

Re: John Resig: JavaScript as a First Language

#49

Javascript is an absolutely horrible language to use for such purposes. There are far too many gotchas. See the following for numerous examples: http://stackoverflow.com/questions/1995113/strangest-languag...

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 bro…

The fact that something is popular doesn't make it necessarily good, so your best argument is no argument at all. Same as with English - no connection whatsoever to a programming language, it's a bad parallel.

Re: John Resig: JavaScript as a First Language

#50
The language picked doesn't matter as much as what you can (quickly) do with it.

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.

Post reply on HN