Skip to content Skip to sidebar Skip to footer

Justifying Crockford Claims

I have read Crockford's JavaScript: The Good Parts and have used his validator JSLint. I am sometimes left wondering the justification behind his recommendations. Below is a list o

Solution 1:

You're right, Crockford doesn't very often substantiate his practices.

For example, defining vars somewhere other than the top of the scope is fine in my opinion, as long as you're aware. Javascript will hoist them to the top of the scope anyway. Furthermore, I think its actually beneficial, because you can easily pick out the initial value of a variable, all you need to do is look for the var.

I also think switch-case fallthroughs are very beneficial if you know how to use them. Particularly for writing something like a very complex state machine.

if and for's with a single statement following them, without curly braces is also fine. People have been writing C this way for decades.

If you're aware of what constitutes the end of a javascript statement, semicolons aren't necessary either. Semicolon insertion isn't random, it's not undecipherable contrary to popular belief.

Crockford is well known for trashing regex's...which is terrible. Very powerful (and fast) lexers can be written using regex's as the lexemes/rules/grammar/whathaveyou.

For the most part Crockford knows what he's talking about, but don't take his personal style as gospel. It's very unsubstantiated in my opinion. Some of the best javascript coders I've seen are in direct opposition to Crockford's style with regards to their code.

edit: I don't see why this question was closed. It can be discussed objectively, and is worth talking about.

Post a Comment for "Justifying Crockford Claims"