JavaScript: The Good Parts
by Douglas Crockford, Dec 2008, 978-0596517748
It is interesting that I never really picked up JavaScript seriously before, though it has been the language of the web for over 10 years. By serious, I mean of course I have produced a few code snippets in it, but I’ve never even bothered to actually learn the syntax. You know, most people write JavaScript just like this, cut-n-past, trial-n-error. The perception of the language for most people is quite lame. Well, it turns out not to be lame at all.
This book to JavaScript is very much like Martine Fowler’s book to UML. I liked UML Distilled so much. I prefer the approach of learning by the best yet small parts first, at least as a start. Not only the learning curve is made more appealing, but those not-so-useful parts are avoided if we don’t ever use them. Why bother if I never used diagrams other than class, activity, or sequence diagrams in UML? Wouldn’t it be great to just learn how to use those 3 diagrams?
In this book, Crockford talks about JavaScript only. No DOM, no browser, pure JavaScript, simply the language itself. He also only focuses on a subset of JavaScript. He calls this subset “good parts”, which is a selected set of constructs and concepts in the language he considers good for programming. So what are the good parts of JavaScript?
- loose typing
- expressive object literals
- functions
- prototypal inheritance
Personally I think the most important concepts to grasp in JavaScript is the prototypal inheritance and functions. Chapter 3 has a great introduction to JavaScript’s object model and how prototype works. Chapter 4 introduces functions, including the function scope, closure, and the 4 kinds of function invocation pattern. The usage of constructor is also introduced in this chapter to let you understand what the following code snippet does and how it works:
var Quo = function (string) { this.status = string;};
Quo.prototype.get_status = function ( ) { return this.status;};
var myQuo = new Quo("confused");
document.writeln(myQuo.get_status( ));
Understanding this is vital to either pseudo-classical or prototypal inheritance, which are introduced in chapter 5. Crockford considers pseudo-classical inheritance as a “bad” part of the language and advocates the usage of prototypal inheritance or even functional style instead.
These 3 chapters are probably the most important ones in the book (chapters 3, 4, and 5). The rest mostly introduces various parts of the languages by mentioning what should be noted when using them. The style is more like “gotchas”. In the appendices, Crockford also lists the awful and bad parts of the language he thinks you should be aware of (the awful parts) and avoid (the bad parts).
This book is very good in helping understand the core parts of JavaScript. Though the book is recommended by most people, its intention (using only “good” parts of the language) is rather controversial. For example, some don’t agree that pseudo-classical inheritance as bad part, but some agree that given 2 ways of doing the same things, why choosing the confusing one. Nevertheless, it’s always a good thing to know the opposite sides before you make your mind.
I do have a slight complaint about the book. Some places are inconsistent across the whole book. For example, Crockford has provided a very useful method for creating objects with the ability to designate their prototype objects (so you don’t need fiddle with the use of “new” operator). However, most of the time he calls this method “Object.prototype.beget” in the book but in the provided source code it was named “Object.create” (which is quite confusing, isn’t it?). Checking from his Prototypal Inheritance in JavaScript, it’s obvious that many places mentioning “Object.prototype.beget” was not updated accordingly while introducing the improved version of that method into the book. The same problem also exists in the way he introduces to identify array object type, which is inconsistent between chapter 6 and appendix A.
Another one I found rather annoying is that his terse explanation is sometimes, well, too terse. For example, while mentioning the wrapping of JSON text from the wire in parentheses, he simply explains:
The concatenation of the parentheses around the JSON text is a workaround for an ambiguity in JavaScript’s grammar.
which was too terse in my opinion.
Overall I really like this book. It’s light but deep, and yet easy to grasp.
Almost every useful/interesting web site requires a password (Digg, del.icio.us, you name it). If you want to play with them, you’ll need to register. To register, you’ll need a password. It’s just the way it is on the net these days.
However, it’s a nightmare considering the number of my daily visited web sites.
Well, I don’t know how you handle it, personally I have my own mental system for this. Obviously I shouldn’t use the same password for every web site. I don’t trust anyone, not even Google (do you?). Therefore, I use a few primary words plus some special characters to generate a unique password for each site. For example, for web site foobar.com I might choose a primary word foobarcom mixed with 6&8 to generate a unique password foo6bar&com81.
That’s for generating passwords, the easy one. The hard one is to actually remember them. Currently I rely on Firefox2. But there’s one problem: it’s hard/troublesome to keep sync between multiple computers. Also, if I can’t use my own computer, I’m in trouble.
A more thorough refection on this issue could be found here: More on Passwords. And there’s a new way of handling it: Web Password Hashing.
Basically PwdHash lets you generate a unique password for each site based on a primary word you choose. Yes, it’s a little like my system described above but without requiring you to remember the special characters (and how to mix them with the primary word). So now all you need to remember is a few primary words (and on which web sites they are used).
PwdHash is a Firefox extension and is very easy to use. Whenever you need to enter a password (for a specific web site), just press F2 (or a special prefix “@@”) before you type your chosen primary word. PwdHash would generate a unique password for this site (only) based on the primary word you type3.
Please bear in mind that I don’t really think it’s a good idea to use the exact same method for treating your critical passwords. Be very serious about your critical, secret passwords.
Keep your secrets in you mind only, or it is not secret anymore.
1 Well, this might work for non-critical web sites. But for other critical, life-supporting sites (like E*Trade, NetBank), using the same system to generate passwords is simply unacceptable. It is wise to keep them completely separate from those used for non-critical web sites. If you’ve never been worried about it, you should start to worry. ↑
2 Again, that’s for normal non-critical web sites. For critical passwords, I use Oubliette. These days, web sites start to require you to change your passwords every few months. I really can’t remember them without some kind of help. ↑
3 If you don’t know what hashing means. Hashing is a process for generating unique word from a given input. It will always generates exactly the same word if the same input is given. And by unique we mean hashing will generate a completely different word if a different input is given (even just a single character change). ↑
The sequels are getting longer and longer and finally there comes the finale. I really can’t wait longer ... I definitely will get one on the very first days when it gets to the market.
Oh! This time remember not to read any news from July 21th until you finish reading it. Last year it was too late when I realized I knew the ending before I even got the book. I just can’t get why people would like to know who gets killed and what the ending is on the very first day the book is published (from newspaper!!). Sham on you whoever wrote that on paper!
Besides the recent relaunch of this site with a new theme, you might not notice that I’ve made a transition of the hosting service. It took me almost a full month to complete the transition ...
Well, that’s a long story but let me start on my hosting service first.
I’ve been a faithful customer of ICDSoft for quite a long time (more than 4 years). Don’t misunderstand me, I did not say they provide lousy service. Quite contrary to that, they have the best customer service I’ve ever seen. Though they don’t provide telephone support along with my cheap hosting plan, they do have an almost real-time on-line customer service. During the last 4 years, I’ve opened 20 support tickets to them and each of them was responded/resolved within 5 minutes. These tickets were opened both at day and night. I have to say they really take customer support very seriously (considering my hosting plan only cost $4 a month).
So what’s good about ICDSoft?
- Cheap!
- Damn superb customer service !!
- Support all major scripting languages (php, perl, python, ruby ...). This is a must for developers like me.
- Generous. My hosting plan initially has only 333MB but now it has grown to 1GB (for free!). They occasionally upgrade all plans for free.
- You get to choose the physical location of your server (only two options, HongKong or U.S.). This might be beneficial if your audience are mostly in Asia.
- See the plans for yourself
Seriously, why did I switch? Just got bored?
Well, sort of :) I was somewhat disappointed at the following facts:
- No FastCGI support. This is probably the main reason as I really couldn’t stand for the slowness of my Rails application.
- No shell access (unless you pay more). So I didn’t have the leisure to install whatever I wanted but not provided by them (for example, subversion repository).
That led me to DreamHost. What’s good about DreamHost?
- FastCGI support.
- Shell access, either telnet or ssh. Now I can have my own subversion repositories. I even installed svk :)
- Incredibly large disk storage (200GB!! Better yet, it grows every week!). This made my remote secondary backup plan feasible.
- Cheap. I really doubt if there’s any better price tag on the net with the same set of service ...
- See the plans by yourself.
Unfortunately, there’s no perfect world. On one hand, I really miss the customer support of ICDSoft (yes, I’m implying DreamHost only has so-so customer support compared to ICDSoft). On the other hand, DreamHost’s plan gives me what I want for so long. However, DreamHost’s server downtime seems to be a little bit more frequent (at least so far). Also, the FastCGI support is not yet solid enough (except for Rails) at the moment.
Oh well, I probably would stick with DreamHost for now. I really can’t afford of having another transition back to ICDSoft (unless I got bored again someday :p).
Yeah, we all work in cubicles, but everyone works in a cubicle up to and including the CEO!
The CEO? Does the CEO really work in a cubicle?
Well, he has a cubicle, but actually now that you mention it there’s this one conference room that he goes to for all his important meetings.
I cound’t describe it better.
I’m not complaining, but with those bosses? Please, please stop talking about how great or how generous they are (because of) having the same small, crappy, noisy cubicles as we developers have. You just always ended finding that bosses always stay in the conference room or in the hallway (and probably the ultimate source of all the noise).
And if you dare to ask them about it, they probably would say it’s policy. Which is always some kind of bureaucracy anyway.
SQL is never hard but definitely tedious. You know what I mean.
Occasionally I tend to create a relatively complicated query instead of fetching the data back and do the processing in my code. Sometimes for the performance, and sometimes just because I like challenges.
I know, I never am a SQL expert. But anyway, it might help.
Say we have a table like the following:
| Department | Employee | Salary |
|---|---|---|
| A | John | 1000 |
| A | Michael | 1200 |
| A | Bob | 880 |
| B | Ted | 2000 |
| B | Jane | 2000 |
| C | Ally | 2000 |
| C | Kent | 4000 |
And we want to get a query of all employees having the highest pay from each department. What SQL query should we have?
Well, first we need to find what the highest pay of each department is:
SELECT DEP.DEPARTMENT, MAX(DEP.SALARY) FROM DEPARTMENT DEP GROUP BY DEP.DEPARTMENT
This will give you a list of department with its highest pay. But we do want to fetch the complete row so that we could know who that employee is. So how do we proceed from here?
We need sub query and EXISTS predicate:
SELECT *
FROM
DEPARTMENT
WHERE
EXISTS (
SELECT
DEP.DEPARTMENT
FROM
DEPARTMENT DEP
GROUP BY
DEP.DEPARTMENT
HAVING
DEPARTMENT.DEPARTMENT= DEP.DEPARTMENT AND
DEPARTMENT.SALARY = MAX(DEP.SALARY)
)
The result looks like this:
| Department | Employee | Salary |
|---|---|---|
| A | Michael | 1200 |
| B | Ted | 2000 |
| B | Jane | 2000 |
| C | Kent | 4000 |
The speed of this query doesn’t seem very bad. In fact, it performs far better than I originally thought since it involves sub query.
Have you heard of PMP? Probably you have, I guess.
My feeling about PMP (or any other certificate) has always been somewhat in line with Scott Berkun: License to manage?. Certificates are nice to have, but not requirements.
Most certificates today have specialized learning guide for you to quickly grasp everything you need to get those certificates. I do admit the acquiring a certificate itself does add some value in learning a topic. It gives you a goal and some study area (most of the time with a truly excellent study guide). I do tend to acquire certificates as bonus for learning a new topic (if I don’t need to pay for them). It might not be useful, but certainly not harmful.
Well, PMP is by far the most painful one I’ve ever tried (and probably the most valuable one). Naturally there’s an excellent study guide for it:
PMP Exam Prep, Fifth Edition: Rita’s Course in a Book for Passing the PMP Exam
by Rita Mulcahy
I would say the book itself (along with its simulation software) should be enough for you to pass the exam. I have read it thoroughly for 3 times and have done 4 simulations (all with scores much higher than the passing criteria).
BTW, I did take several project management courses during the last few years. So my experience might not be a perfect match for you.
OK, I admit I cannot live without Bloglines.
I read news, technical publications, and friend blogs everyday on my Bloglines page. Almost everything has feed these days and it’s just damn convenient to be able to have-it-all in a single place.
Well, almost ...
One of the strangest thing keeps knocking my head is that there’s no stock quote feed (or at least I’m not aware of). There are a lot of web site for you to check the current stock quote, but none of them provide a feed. All I want is a simple feed of stock quote so I can read it on Bloglines once a day (or maybe once a week). I don’t want to maintain a portfolio on a financial portal site and have to manually log in everyday just to learn the current stock quote.
Luckily, someone has a solution: Yahoo stock to RSS converter. It’s a PHP script which parses Yahoo’s stock quote data to generate a feed. Simply put it on a PHP supported server and you get a personal stock quote feed for your own needs (there are quite a few parameters which let you tune the generated RSS content).
Since I’m using it with Bloglines, I have modified it a little bit to fit Bloglines’ interface. The original version makes Bloglines treat each quote update as a new entry. That ends up generating lots of entries for each stock (Yahoo’s stock quote updates every half an hour) and annoys me since I only care about the most current quote. Here’s the modified version (download and rename it): stockrss
I have been using MoinMoin and trac in my project for a long time. They are really great tools for development work. It’s imply damn cool to merge bug tracking with wiki (and vice versa).
However, it’s another story when you want to use wiki for project management purpose. One thing that keeps annoying me was that we use Lotus Notes in our company. My work as a project manager has to copy and paste those business emails into wiki. Since nobody would write their emails in wiki format, and in order to make email looks reasonably ok, I have to manually edit each email before I put it into wiki. What a nightmare!
That’s not respectable work anyway.
To make my life (and the team’s) easier, I hacked out a parser for just that purpose. The parser recognize the content you copied from Lotus Notes and will format it in an easier-to-read style (by making email headers stand out). Now I just need to copy-and-paste (but no edit anymore!).
The most notable new thing (to me) in this version is that now we don’t need to install a separate application server for the reporting application. CruiseControl can now embed a Jetty server so it is even easier to set it up.
Oh, the bug of detecting Subversion modification set introduced in version 2.2.1 is also fixed (mentioned in Self-Controlled CruiseControl). It was strange that I couldn’t Google any information related this bug (was it only me?). Anyway, the problem is gone in this new version.
I also complained about the inability of adding/removing projects without restarting build loop before. Guess what? It is now possible to achieve Self-Controlled CruiseControl.
Another major new feature is that we can now define Ant style properties in the configuration file. It should be a lot easier to structure the configuration file (also a lot simpler).
The new release includes many fixes and several new plugins. For example, a new RSS publisher is added (as well as RSS support in reporting pages). There is also a preliminary support for distributed building. Check out the release note for yourself and get it now!




