Hacker News new | ask | show | jobs
by chalupa-man 3558 days ago
I'm surprised to see JS described as easier than Python. I'd say it's considerably harder and more complex. The first reason being that it forces you to think about asynchronosity constantly, and that's something a beginner's going to struggle with -- not just the idea that your code won't run in order, but that there are so many ways to deal with it (callbacks, promises, async/await, event emitters) all with their own tradeoffs. The second being that the standard library is anemic, so a ton of what you'd just hit the Python Stdlib for you have to either write yourself or sift through npm to find. Then there's the wildly varying code styles: this person/book encourages the traditional imperative style using loops and mutations, this other person encourages a functional style using folds and maps to do the same things. Prototype-based inheritance is less intuitive than class-based inheritance. There are multiple ways to do everything, even things as simple as variable assignment (var, let, const, implicit global, function foo() vs let foo = function() vs const foo = () =>), weird invisible things that trip you up like hoisting and how creating a global variable looks exactly the same as reassigning an existing local variable. New users will inevitably encounter the multiple competing module systems and either confuse syntax or fret about which to use.

I agree that it's cancerous, and that making the server side more accessible to front-end developers isn't worth all the problems Node introduces long-term. My dream is still a statically-typed version of Erlang.

7 comments

You are absolutely correct. JavaScript is by no means as easy for a beginner than Python. Once you get beyond the most basic of programs , JavaScript starts throwing a lot of crazy concepts at you like prototypical inheritance,hoisting, and this (and I'm only counting es5)
The most intimidating part of Js isn't even the language, it's the ecosystem.
When you bundle it with HTML/CSS it's an easier start to GUI development then python.
> My dream is still a statically-typed version of Erlang.

Your (our) dream is about to come true: https://github.com/j14159/mlfe

Don't confuse Node with Javascript. Node and the browser are where all the async behavior comes from, not JS. Specifically; if you've ever done any backend coding in Meteor, there is practically no async behavior at all.

But I do agree: Sometimes I see people try to push Node/Express as a good choice for teaching basic APIs. Its not the worst choice, but its startling how easy it is to forget how insanely confusing async callbacks are for new devs.

> My dream is still a statically-typed version of Erlang

So something like Haskell?

http://learnyouahaskell.com/introduction#so-whats-haskell

I agree completely, but doubt I could have put it as eloquently as you did.

I personally have found my go-to tool for web development - Scala. It is a breeze to work with, and I advise anyone looking to develop web apps to give it a try, especially if you're tired of dynamic languages

> weird invisible things that trip you up like hoisting

Huh? How can you get tripped up by hoisting? I'm genuinely curious.

Any time you have a closure that captures the hoisted variable. Most often, this happens with loops. Say, someone might start with this:

  for (var i = 0; i < 100; ++i) {
    foo().then(function() { bar(i); });
  }
Then when they realize why this doesn't work, try something like:

  for (var i = 0; i < 100; ++i) {
    var j = i; // this is inside the block, so it's scoped to it, right?
    foo().then(function() { bar(j); });
  }
And then that breaks too, and it's not at all clear why.

It's not that other languages don't have similar limitations - Python also doesn't have block-local variables, for example. The problem with JS is that is uses syntax that strongly implies that it does have block scope, but then quietly makes it do something unexpected when you try.

Ironically, the only other language that I know of that has the same exact problem is VB (pre-.NET one) - its "Dim" statement can similarly be used anywhere inside a function, including inside loops and other block constructs, but the scope is always the entire function.

Ok, thanks. I would call that a problem with not having block scope, not a problem with hoisting. Not trying to be pedantic; I was just confused about how hoisting could be such a problem. A language could have variable/function declarations hoisted to the top of block scope rather than the top of function scope.

And as I'm sure you know, JS now supports block scoped variables through `let` and `const`.

Agree Python is easier to learn than JS (at least the basics) but IMO JS has a much nicer environment(the browser) for teaching programming.

Reminds me of these post: http://prog21.dadgum.com/203.html