Tuesday, April 15th, 2008

JavaScript: The Good Parts

Category: Books

<p>http://ajaxian.com/wp-content/images/jsgoodparts.png" alt="JavaScript: The Good Parts" border="0" width="520" height="315"/

Douglas Crockford has an interesting book on the horizon, JavaScript: The Good Parts. When I first heard about the combination of author and title, I couldn’t help but think that it would be a short book, maybe a two pager as above.

But, Douglas has taken a deep look and found some content worthy of a book:

Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. This authoritative book scrapes away these bad features to reveal a subset of JavaScript that’s more reliable, readable, and maintainable than the language as a whole-a subset you can use to create truly extensible and efficient code.

Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. This authoritative book scrapes away these bad features to reveal a subset of JavaScript that’s more reliable, readable, and maintainable than the language as a whole-a subset you can use to create truly extensible and efficient code.

Considered the JavaScript expert by many people in the development community, author Douglas Crockford identifies the abundance of good ideas that make JavaScript an outstanding object-oriented programming language-ideas such as functions, loose typing, dynamic objects, and an expressive object literal notation. Unfortunately, these good ideas are mixed in with bad and downright awful ideas, like a programming model based on global variables.

When Java applets failed, JavaScript became the language of the Web by default, making its popularity almost completely independent of its qualities as a programming language. In JavaScript: The Good Parts, Crockford finally digs through the steaming pile of good intentions and blunders to give you a detailed look at all the genuinely elegant parts of JavaScript, including:

  • Syntax
  • Objects
  • Functions
  • Inheritance
  • Arrays
  • Regular expressions
  • Methods
  • Style
  • Beautiful features

The real beauty? As you move ahead with the subset of JavaScript that this book presents, you’ll also sidestep the need to unlearn all the bad parts. Of course, if you want to find out more about the bad parts and how to use them badly, simply consult any other JavaScript book.

With JavaScript: The Good Parts, you’ll discover a beautiful, elegant, lightweight and highly expressive language that lets you create effective code, whether you’re managing object libraries or just trying to get Ajax to run fast. If you develop sites or applications for the Web, this book is an absolute must.

Combine this with John Resig‘s new book, and we have some good stuff to look forward too.

Related Content:

Posted by Dion Almaer at 8:05 am
15 Comments

+++--
3.8 rating from 47 votes

15 Comments »

Comments feed TrackBack URI

This looks like a good book to grab, especially for it’s pre-release price (most technical books cost way too much). While it is only 200 pages, I am amazed it will come out in so quickly – perhaps Doug used a Ghost (of Netscape) writer? :)
I bet dollars to donuts that some political content is mixed in with the technical. I mean – the title and intro already are a shot, so I assume he gotta say something about Javascript2

Ric

Comment by OpenAjax — April 15, 2008

After programming full time in JavaScript for a couple of years I am not too sure what to make of Douglas Crockford.Sure I understand where he is coming from, but JS isn’t as bad as it is made out to be. Perfectly normal C/Java constructs that people use daily are considered as bad. for(var i=0;i Written in a single line is bad code if you ask Crockford. I just don't agree. The Rhino book will remain the bible, even if it has a few errors still lingering in the latest edition.

Comment by hvendelbo — April 15, 2008

@OpenAjax

I hope political means political in the sense of advocacy that has to do with JavaScript in some way and not some topical content that will be meaningless and irritating in six months. No reason to be divisive in a technical book. I’ll avoid the book if it’s political in a divisive way. I get enough “politics” as it is.

@hvendelbo

Your example is a great point in how JavaScript is NOT C or Java. What is the difference in scoping rules between C/Java and JavaScript? Obviously, C/Java is block-scoped and JavaScript is function-scoped. I used to do exactly what you showed, but have since switched to declaring all variables at the top of the function. That way, the code looks the same to both me and JavaScript, and I don’t have bugs caused by scope leakiness.

I see it more as a maintenance issue than a coding issue. It’s really about clarity, and is especially important if you think you’re going to come back and modify the code later, or if you’re working as part of a team. If JS were block scoped, I’d agree with you. Since, it’s function scoped, I’m 100% disagreeing with you. Trying to pretend JS is C/Java causes a hell of a lot of pain

Comment by Nosredna — April 15, 2008

This good part only applied to ES3. O’Reilly might need to reconsider the book title when ES4 settle down.

Comment by digdog — April 15, 2008

The first and second paragraphs of the quote are the same…

Comment by balupton — April 15, 2008

I was referring to the assertion that you shouldn’t use ++/– and always do {} after for/if. Or for instance, never use Globals. I find that one inspiring actually and think I can get away with it for all but cross frame communication. Attending his presentation on the beautiful subset I started out thinking “I know exactly what you mean” and ended up thinking that he had gone too far. var a;for(a=0;a On the topic of variable scopes they are always tied to the enclosing function. If you program in JS you need to know that along with the nature of closures. Expecting a particular style of coding to save you from properly understanding scopes would be naive(not saying that was your argument btw).As another example that often annoys me in Eclipse(not sure if the test is from JsLint) is regular comparison with null/undefined. There is nothing obscure about comparing with null. It will match null or undefined, which is usually exactly what you want. Comparing with “”,0,false is a different discussion.

Comment by hvendelbo — April 15, 2008

grr; var a; for(a=0;a<5;a+=1) { console.log(“hello”); }

Comment by hvendelbo — April 15, 2008

hvendelbo,

I see what you’re saying. Looks like the formatting here was killing your post-increment and so I assumed you were talking about where to declare your variables.

Every person or team has to make decisions about what is appropriate. I have no problem with how anyone decides. Just saying that I personally think that declaring all the vars at the beginning of functions has a lot more upside than downside. I’ve seen too many bugs caused by people justing C++ habits in JavaScript.

Agree about people needing to understand closures and the power of JavaScript.

I use JSLint, but I turn off a few of its complaints. I agree with you that there’s nothing wrong with pre- or post- increment. I stick by what I said about variable declaration.

Comment by Nosredna — April 15, 2008

I’m not seeing any content to this post in FF, only a title and comments.

Comment by Jon Hartmann — April 15, 2008

i don’t see anything either in FF. also Google Reader shows nothing.

Comment by AaronHeckmann — April 15, 2008

I’m not seeing any content to this post in the source view on FF… is there even content to this post at all?

Comment by Jon Hartmann — April 15, 2008

Maybe there are no “Good Parts” after all.

Comment by Steve — April 15, 2008

@Nosredna: It’s political in the sense of advocacy (open source, open standards, open process) – trust me, there’s nothing related to traditional politics, here.

Comment by JohnResig — April 15, 2008

>>It’s political in the sense of advocacy (open source, open standards, open process) – trust me, there’s nothing related to traditional politics, here.

Ah, good. I can handle that. :-)

Comment by Nosredna — April 15, 2008

There’s also a Missing Manual coming in June from O’Reilly. 500 pages. Wonder if that’ll be any good.

Comment by Nosredna — April 15, 2008

Leave a comment

You must be logged in to post a comment.