Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: The JavaScript Way, a new book for learning modern JS (github.com/bpesquet)
39 points by bpesquet on Feb 27, 2017 | hide | past | favorite | 23 comments

I appreciate the effort that went into this, and it's certainly important to have a good clear reference on JS. Unfortunately, I can't support the effort to aim this at beginners, because I think JS is an extremely poor choice of language for first-time developers. It's poorly designed, with too many side effects and edge cases and confusing behaviors to be a good choice for a first language. It will bog down first-time learners with weird minutiae, and it will do that because it is a poorly/hastily built language that is being used in ways it was never intended for. I realize JS is ubiquitous and easy to access (since all browsers have it), but that doesn't make it the right choice. It's just too broken.

Accessibility beats out all other concerns; why is JavaScript so popular and ubiquitous? It doesn't really matter if you like it or not - especially from a 'purity' point of view.

80% of everything is crap.

The weird edge cases in JavaScript are easily avoided when teaching a subset of es2016 to new programmers.

The basics: variables, loops, functions, etc... are all fine. It's got pretty good functional programming support, too, for beginners.

In terms of "should one be able to use it," no, it doesn't matter whether I like it or not. A developer who works on the web needs to know JS. That doesn't mean newbie who doesn't know what they want or anything much about development needs to know it, and certainly not that they need to start with it.

It's not a "purity" point of view, it's an "ease of use for the purpose" point of view. JavaScript does weird things that stymie experienced devs - a newbie hitting them will be completely lost. What's worse, as I said, is that it does these things because it's poorly designed/its design doesn't adequately cover all the edge cases it should, so newbies will learn the wrong information about why things do or don't happen.

The edge cases are not easily avoided because you don't know what a beginner will or won't try to do when working on their own. That means that not only might they do an okay thing in most languages that doesn't work in JS, but that they may also do something BAD that DOES work in JS, because JS is weird. For instance, the way JS handles variable hoisting and scoping is bonkers compared to most other languages - not stuff you can avoid while learning to program, and making it easy to learn the wrong practice as a result.

"80% of everything is crap" is a good thing to know when doing development work, but it isn't helpful when learning. The goal of learning in this context is mastery of the basics of development; 80% won't be good enough.

> you don't know what a beginner will or won't try to do when working on their own

This is true regardless of which language you use to start with. Computing in general is so ridiculously over-complex and constructed entirely of layered kludges, that beginners are going to trip and fall into lots of these crevasses no matter what, unfortunately.

The first lesson advantage of being able to start the coding immediately (everyone has a browser) is not to be dismissed. If you try to do this in Python - otherwise an excellent choice - you will spend the first ~day of the course installing Python and explaining about command lines, editors and the REPL.

This seems trivial to us, but it's a huge hurdle for many first time programmers. The JS version of this is "go to this URL, then right click and select Inspect. Start typing in the console."

This is exactly right. JavaScript was a great beginner language, but it has now been "professionalized" with ES6, requiring insane build chains, transpiling, shims, all this stuff just to run a basic web site.

JavaScript has been ruined by professional programmers (mostly Rubyists) who never learned how to use the object model, or how to structure functional code well. So we get ES6 classes and promises and async and all of this junk that makes the language impossible to build and debug.

And I say this as a full time JavaScript programmer of ~5 years, after ~5 years of Ruby. I love both classic JavaScript and Ruby, but ES6 is an abomination.

    node -v

I don't think JS's problems come just or mainly from its "professionalization." The big problems: Hoisting and scoping weirdness; ambiguity around common operators and type comparisons; poor behavior of "this", and on and on, are baked into the spec. JS is bad at its core level, because it is inconsistent and has broken functionality.

I think all of those things are great. I use this when I need a declarative data structure. I use nested scopes when I need a compositional data structure. Otherwise I use pure functions. Which is most of the time.

I love having these three choices and only these three choices. I think class inheritance, promises/async, and other similar features add complexity for little gain.

I used to revel in using fancy features. I was so excited when I found a real need for a DSL in one of my Ruby applications. I built it. I felt like a rock star. Then 12 months later I realized I could have wrote the same code, more understandably, with functions and a few arrays to index data.

You refer to JS core as "poor" and "bad" which are not very descriptive words. I am sure you have material criticisms but what are they? I read every JavaScript critique I see, and so far they mostly boil down to "it's not C" or "it's not Ruby" or "it's not Haskell".

Yah, it's not. It's simpler and unless you are building a compiler or a video game it's often better because of the simplicity.

The problem with JavaScript, IMO, is that people come from other languages, don't actually learn how the JS primitives are best used, and prematurely try to extend the language. See Promises, see classes, see async. These are all features that were only added because the developers couldn't be bothered to learn how to use exactly the features you mention.

You can argue this as bad usability on the part of JS, but the reason it gained so much traction is not just because it was in Netscape....

These are actually amazingly powerful feature implemented in a small space. As a beginner they are incredibly usable. It's only hard for experts coming from C or Ruby, who are the people wrecking the language with extensions. Lispers seem to get it.

Java is more than accessible enough for beginners. You can download eclipse, jre jdk on Windows Linux and Mac. I think Java and C# are superior languages: (they even have integers as a specific type!!)

This is great. Also wanted to toss out its asynchronous nature is not great for beginners either in my opinion.

Why not? What language makes dealing with asynchronous problems easier for a beginner?

    const getTweets = (username) => return fetch(`https://api.twitter.com/${username}`)
Really isn't that bad, although you have to know promises. With regular callbacks, I guess you have to know that functions can be passed as arguments, but you'll have to learn that quite soon regardless.

    const getTweets = (username, callback) => {
      const req = new XMLHttpRequest()  
      req.onload = function () {
        return request.status === 200 ? callback(undefined, JSON.parse(this.responseBody)) : callback(Error(request.statusText))
      req.onerror = callback
      req.open('get', `https://api.twitter.com/${username}`, true)
    getTweets('nevon', (err, tweets) => {
      if (err) {
      } else {
Most of the confusing crap in there is because of XMLHttpRequest, not asynchronicity.

With async functions, which I personally am not a huge fan of, you can get synchronous looking code if you believe that's more beginner friendly:

    async function getTweets (username) => {
      const response = await fetch(url)
      return response.json()

Lol, asynchronous is harder to reason about than synchronous. Plus just about anything goes in the browser. You can put anything anywhere and alot of things are global by default! And as a noob you have enough on your plate learning OOP and REST. I'm glad I started with Ruby and Java and got really good at OOP and clean compartmentalized code before jumping into the madness that is browser land. Just my opinion.

I don't think "is this behavior synchronous or asynchronous" is where we should start when teaching new developers, period.

Passing functions and lambdas and closures is not what newbies are learning...That's like saying: "building bridges isn't hard, you just have to learn kinematics and materials science...But you have to learn that anyway.."

Which language do you suggest for beginners?

I'd suggest something relatively standardized and regimented. Python, C#/Java, even a Lisp variant like Scheme are all decent choices.

But of all the languages not to pick, I'd content that JavaScript is one of the very worst. (PHP and anything Visual Basic are honorable mentions.)

> using latest language standard(ES6/ES2015), avoiding awkwardnesses from the past

> `Object.create`


Care to elaborate?

Understanding prototypal inheritance seems essential to me, and Object.create() is the cleanest way to show it in action.

The book also presents the alternative class syntax and numerous ES2015 additions like block-scoped variables and arrow functions, to name a few.

It explicitly states it avoids the past and focuses on es2015, but then talks about old patterns.

I don't consider Object.create() and factory functions to be "old patterns", but YMMV.

How would you teach OOP basics to a JS newcomer then? Using only class without mentioning prototypes?

Bookmarked. Hoping this proves to be the structured intro to web development and JS that I need.

Maybe "Front-End Web Development: The Big Nerd Ranch Guide" is what you are looking for.



We've banned this account for violating the HN guidelines.

Applications are open for YC Summer 2021

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact