2
|
Chapter 1: Good Parts
Fortunately, JavaScript has some extraordinarily good parts. In JavaScript, there is a
beautiful, elegant, highly expressive language that is buried under a steaming pile of
good intentions and blunders. The best nature of JavaScript is so effectively hidden
that for many years the prevailing opinion of JavaScript was that it was an unsightly,
incompetent toy. My intention here is to expose the goodness in JavaScript, an out-
standing, dynamic programming language. JavaScript is a block of marble, and I chip
away the features that are not beautiful until the language’s true nature reveals itself.
I believe that the elegant subset I carved out is vastly superior to the language as a
whole, being more reliable, readable, and maintainable.
This book will not attempt to fully describe the language. Instead, it will focus on the
good parts with occasional warnings to avoid the bad. The subset that will be
described here can be used to construct reliable, readable programs small and large.
By focusing on just the good parts, we can reduce learning time, increase robustness,
and save some trees.
Perhaps the greatest benefit of studying the good parts is that you can avoid the need
to unlearn the bad parts. Unlearning bad patterns is very difficult. It is a painful task
that most of us face with extreme reluctance. Sometimes languages are subsetted to
make them work better for students. But in this case, I am subsetting JavaScript to
make it work better for professionals.
Why JavaScript?
JavaScript is an important language because it is the language of the web browser. Its
association with the browser makes it one of the most popular programming lan-
guages in the world. At the same time, it is one of the most despised programming
languages in the world. The API of the browser, the Document Object Model
(DOM) is quite awful, and JavaScript is unfairly blamed. The DOM would be pain-
ful to work with in any language. The DOM is poorly specified and inconsistently
implemented. This book touches only very lightly on the DOM. I think writing a
Good Parts book about the DOM would be extremely challenging.
JavaScript is most despised because it isn’t some other language. If you are good in
some other language and you have to program in an environment that only supports
JavaScript, then you are forced to use JavaScript, and that is annoying. Most people
in that situation don’t even bother to learn JavaScript first, and then they are sur-
prised when JavaScript turns out to have significant differences from the some other
language they would rather be using, and that those differences matter.
The amazing thing about JavaScript is that it is possible to get work done with it
without knowing much about the language, or even knowing much about program-
ming. It is a language with enormous expressive power. It is even better when you
know what you’re doing. Programming is difficult business. It should never be
undertaken in ignorance.