Live data from Hacker News

John Resig: JavaScript as a First Language

ejohn.org

31–40 of 228 posts

Re: John Resig: JavaScript as a First Language

#31
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.

Re: John Resig: JavaScript as a First Language

#32

Earlier quoted context omitted.

If widest reach is your criteria, Java and C would also be equally good choices. Unless the web browser is special in some particular way that makes it 'more worthy' than other execution environments?

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.

Re: John Resig: JavaScript as a First Language

#33
post #9

Only thing I am not sure about is the focus on "===" - I think it is a pain and fails in too many instances to do what the programmer would expect.

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.

Re: John Resig: JavaScript as a First Language

#34
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.

Re: John Resig: JavaScript as a First Language

#35

Earlier quoted context omitted.

No it's not. Logically, the only other thing that could happen is for an "error" or "exception" be thrown when you do '5' - 3 There's really only 2 choices. Either convert the '5' to a number and subtract, or throw a hissy fit because it's a string. That's not perverse. It's very logical.

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'.

Re: John Resig: JavaScript as a First Language

#36

Earlier quoted context omitted.

Calling your example logical and obvious is only logical and obvious if you're completely trapped within the JS mindset. It's the same as how people defend the absurd semantics of Visual Basic and PHP. It's fine if you like it, but to claim that it's objectively okay is just not supported by fact. It's also worth considering that even if every language has 'gotchas', some of them have far worse gotchas than others. I…

See my comment below. It's not about being trapped in any mindset. It's about thinking logically. Either '5' - 3 results in an error of some kind, or it evaluates to 2. There is no other logical outcome. Javascript chooses to do the latter. I also disagree that starting language matters. It's like saying you need to have a steinway grand to learn the piano properly. Learning is about learning what not to do just as m…

Please do not downvote maximusprime's comments just because you disagree with them.

Re: John Resig: JavaScript as a First Language

#37
post #9

Only thing I am not sure about is the focus on "===" - I think it is a pain and fails in too many instances to do what the programmer would expect.

Can you give examples of it doing unexpected things? I get the feeling the unexpected part about it is your operands are not of the types you thought they were?

Re: John Resig: JavaScript as a First Language

#38

Earlier quoted context omitted.

Calling your example logical and obvious is only logical and obvious if you're completely trapped within the JS mindset. It's the same as how people defend the absurd semantics of Visual Basic and PHP. It's fine if you like it, but to claim that it's objectively okay is just not supported by fact. It's also worth considering that even if every language has 'gotchas', some of them have far worse gotchas than others. I…

See my comment below. It's not about being trapped in any mindset. It's about thinking logically. Either '5' - 3 results in an error of some kind, or it evaluates to 2. There is no other logical outcome. Javascript chooses to do the latter. I also disagree that starting language matters. It's like saying you need to have a steinway grand to learn the piano properly. Learning is about learning what not to do just as m…

Your ideas about what is "logical" are completely arbitrary. Look, I can make up rules too:

* '5' - 3 should return '5', since it's the string '5' minus all the instances of the character '3' in it. There is no other logical outcome!

* '5' - 3 should return an empty string, since it's the string '5' with the last three characters removed. There is no other logical outcome!

* '5' - 3 should return '2' -- since we started with a string, the result should turn back into a string. There is no other logical outcome!

* '5' - 3 should return 50, since the only logical way to do math on a character is to take the UTF-8/ASCII value of it and then do the math. There is no other logical outcome!

* '5' - 3 should return undefined, since subtracting from a string typically doesn't produce a reasonable result. There is no other logical outcome!

You have provided absolutely no rational basis for discriminating between the merits of these choices, so your claim that Javascript's choice is one of exactly two "logical" ones is bizarre. If you think Javascript's choice is better, give a reason why it's better, don't just say that it's better.

Re: John Resig: JavaScript as a First Language

#39

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.

Well, I grew up in a day when it was even easier.

  * Buy home computer (ZX81)
  * Turn on
  * 10 Print "Hello world"
  * run
I don't think the instant gratification and ease of use did me any harm.

Re: John Resig: JavaScript as a First Language

#40
Interesting Idea.

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

Post reply on HN