Live data from Hacker News

John Resig: JavaScript as a First Language

ejohn.org

21–30 of 228 posts

Re: John Resig: JavaScript as a First Language

#21

Earlier quoted context omitted.

Disagree... for example from the link: In JavaScript: '5' + 3 gives '53' Whereas '5' - 3 gives 2 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…

That's definitely not obvious. Some people think in patterns or generalizations. String [binary_operator] Number = String String [binary_operator] Number = Number That's just begging for further explanation. Explaining JavaScript is probably more challenging than say Java. Java has many keywords and usages, but when it comes to explaining the concept of those keywords/semantics to students, it may be a little bit les…

OK here's plain english simple explain...

Left hand side is a string, and "+" is string concatenation as well as addition. So '5' + 3 = '53' (String concatenation). Just as "Hello" + 1 would equal "Hello1". The right hand side is converted to a string.

Left hand side is a string, but "-" is subtraction for numbers. JS converts the '5' to a number, then subtracts. So '5' - 3 = 2 (Numerical subtraction).

That's the explanation, and it's not terribly hard to get past.

Re: John Resig: JavaScript as a First Language

#22
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?

Re: John Resig: JavaScript as a First Language

#23

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…

The time wasted learning the quirky semantics and special rules covering each operator and data type in JavaScript could be better spent learning to reason about algorithms and data structures in a less confusing language. Not all learning is equal, and not all challenges are exactly the same.

The claim that by hindering a newbie programmer's attempts to express themselves will make them more effective in a better language is ridiculous. Even if it's true, it's missing the point - your goal when teaching newbie programmers should be to teach them good habits and generally applicable skills, and most importantly, you want them to love programming.

Having to memorize arcane minutiae and spend tons of time debugging problems caused by stupid design decisions is not going to make people love programming. JavaScript is tremendously accessible by virtue of its ubiquity, but that does NOT implicitly make it a good language for learning to program. Its numerous flaws and divergent implementations will drive away beginning programmers that might otherwise learn to love programming if presented with a better environment.

Re: John Resig: JavaScript as a First Language

#24

Earlier quoted context omitted.

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.

While that may be true (it's definitely take more steps to get your feet wet in Java), my experience with JS is otherwise until Node.JS arrives. I just don't have time to twiddle with document object (DOM API) just to see results.

Some people dont have time to twiddle with a crapload of OO abstractions/interfaces just to see results either.

Re: John Resig: JavaScript as a First Language

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

Agreed. I also think that the reason a lot of us stuck with programming was because we loved the feeling of making something fun that we could play with. This is arguably a lot easier to do from the start with JavaScript than with Java or Python because one of the main applications of JavaScript is visual manipulation. Generally the first Java or Python programs you make are used from the command line. I think that when someone's starting out with something like programming, you want to put fun before "educational value" (correct OOP design principles) to give them that itch.

I think using something like d3.js or processing.js would be a good place to start: http://mbostock.github.com/d3/tutorial/circle.html

That's a FUN tutorial that could easily dovetail into a larger project.

Re: John Resig: JavaScript as a First Language

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

There is nothing unexpected in strict equals behavior, quite the opposite. This is unexpected for most:

    '[object Object]' == {}

Re: John Resig: JavaScript as a First Language

#27

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.

The claim that everyone has a profiler, debugger and REPL is blatantly false. Only a subset of commonly available desktop browsers include those features, and out of those, only recent versions do. Mobile web browsers don't include any development or debugging tools.

The cost of installing Visual Studio or Eclipse is pretty small considering that you only have to do it once. Compare that with the cost a newbie programmer pays every time they use the comparison operator or the arithmetic operator and they now have to consult their reference text to figure out what the operator is going to do and whether they're using the right operator.

If your goal is to lead someone into a lifetime of programming and help them enjoy it, choosing a language in order to avoid a pesky 15 minute setup cost for a compiler is tremendously short-sighted.

Re: John Resig: JavaScript as a First Language

#28
post #10

Earlier quoted context omitted.

It's logical and obvious if you already know the language; otherwise, it's perverse. I had to read your comment (the initial edit of it) twice to be sure you weren't being sarcastic.

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 strings and otherwise type coerce into numbers. Then:

'5' + 3 = 8 '5' - 3 = 2

To someone who doesn't code Javascript for a living, the above seems like a far more consistent and useful behavior.

Re: John Resig: JavaScript as a First Language

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

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

Re: John Resig: JavaScript as a First Language

#30

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

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!

Post reply on HN