Skip to main content

JavaScript: Quickies

Concerning MochiKit: It's well written. I like the Pythonic feel. I like the docs, the humor, and the heavy regression testing. I even like the code, which is a huge compliment!

Concerning DojoToolkit: I like the fact that it's a community of people who have each given up their own framework to work together. I like the mailing list. I like the event system and the package system (although I haven't used it yet). I don't like the fact that it doesn't feel quite as polished by a perfectionist as MochiKit. I also hate the part of the style guide that says you should not use a space before "{" in:
if (foo){
I don't know of any other style guide that suggests this.

Does this mean I'm going to pick one over the other? Nope. Both have good parts. Fortunately, they're compatible. It looks like I'm going to have to use them both. Ideally, the guys from MochiKit would take a bunch of their stuff and shove it into DojoToolkit. Then the guys from DojoToolkit would change their style guide. (Yes, I readily admit I'm a freak. No, my psychologist doesn't think there's anything he can do for me. ;)

You may wonder why I didn't mention Prototype. I've heard that it has no documentation and that it doesn't play nicely with other JavaScript libraries. I'm sure that it's very nice and that it has a lot of cool features, but these are things that I feel are important.

Also, I just read "DHTML Utopia: Modern Web Design Using JavaScript & DOM". I'm really pleased to find a modern JavaScript book. It was short, yet I got a lot out of it. On the other hand, there were many errors. I think the editing left something to be desired. Furthermore, it reinforced my belief that the intersection of good JavaScript programmers and really good software engineers is really small. There were many code snippets where too much code was duplicated instead of put into some utility function. I wish they had a technical editor who suffered from chronic analness like I do. Nonetheless, it was a pretty good book, and I thank the author for writing it.

As a last note, why have I made it through two DHTML books yet never had the prototype system explained as well as this paper explains it?


Thanks for the compliments on DHTML Utopia. I'm sorry to hear that you found errors, although I fear that wrapping everything up in utility functions makes for tight code but complex and fragmentary explanations. Nonetheless, the words of wisdom are appreciated.
jjinux said…
Hey Stuart, thanks for your response! I definitely understand where you're coming from, and that had indeed occurred to me. Just as you made a function for addEvent, I wish you would have made a function for:

var target = window.event ? window.event.srcElement : e ? : null;
if (!target) return;


if (window.event) {
window.event.cancelBubble = true;
window.event.returnValue = false;
if (e) {

(Hmm, Blogger won't let me indent things or use a pre tag.)

That would have saved a lot of duplication.

Anyway, thanks again for an extremely useful book! I definitely feel like I have a masterful grip on the subject now.
I understand the theory behind wrapping those things, but it's not easily possible. For example, I can't just create a "getTarget" function, because if no target is available then I have to return from the event handler. So, my handler would have to say something like:

var target = getTarget(e);
if (!target) return;

which is not a lot simpler than what I actually *do*, and requires me to set up another function...
jjinux said…
Yep, I understand that completely. That's why it's nice to have a wrapper (perhaps put in place by addEvent) so that by the time your event handler is called, the event is passed to it and that event object is sane and has a sane method to cancel propogation, etc. That is, all these difficulties can be straightened out before the application's event handler even gets called. That's what Dojo does, of course, and I don't think it'd be too hard to have addEvent setup this wrapper implicitly. Of course, I definitely respect your argument that you were afraid it would decrease readability.
I agree with the idea that that's what Dojo does, and there's a reasonable case for using Dojo or some similar library in your code. However, I thought it was important to show people what's actually going on under the covers; using Dojo might make you more efficient, but it's a job for "Dojo Utopia". I admit that I used the Sarissa library instead of raw XMLHTTP, but XMLHTTP stuff falls the other side of the "this is too much of a pain to do manually" line, to my mind.
jjinux said…
Sorry, perhaps I wasn't clear. I wasn't suggesting that you teach Dojo. Afterall, I'm interested in how to write libraries like Dojo from scratch. I'm just saying that you made addEvent into a useful library function. It wouldn't be much harder for addEvent to automatically generate a wrapper function for each event handler so that that event handler got an event object that had a reasonable, cross-browser API. It's something that you could discuss in the book when you discussed addEvent. Then, for the rest of the book, you could just use it without thinking about it. Hopefully that was more clear. If you'd like, I can send you the kind of code that I had in mind. Thanks again for your responses!

Popular posts from this blog

Ubuntu 20.04 on a 2015 15" MacBook Pro

I decided to give Ubuntu 20.04 a try on my 2015 15" MacBook Pro. I didn't actually install it; I just live booted from a USB thumb drive which was enough to try out everything I wanted. In summary, it's not perfect, and issues with my camera would prevent me from switching, but given the right hardware, I think it's a really viable option. The first thing I wanted to try was what would happen if I plugged in a non-HiDPI screen given that my laptop has a HiDPI screen. Without sub-pixel scaling, whatever scale rate I picked for one screen would apply to the other. However, once I turned on sub-pixel scaling, I was able to pick different scale rates for the internal and external displays. That looked ok. I tried plugging in and unplugging multiple times, and it didn't crash. I doubt it'd work with my Thunderbolt display at work, but it worked fine for my HDMI displays at home. I even plugged it into my TV, and it stuck to the 100% scaling I picked for the othe

ERNOS: Erlang Networked Operating System

I've been reading Dreaming in Code lately, and I really like it. If you're not a dreamer, you may safely skip the rest of this post ;) In Chapter 10, "Engineers and Artists", Alan Kay, John Backus, and Jaron Lanier really got me thinking. I've also been thinking a lot about Minix 3 , Erlang , and the original Lisp machine . The ideas are beginning to synthesize into something cohesive--more than just the sum of their parts. Now, I'm sure that many of these ideas have already been envisioned within , LLVM , Microsoft's Singularity project, or in some other place that I haven't managed to discover or fully read, but I'm going to blog them anyway. Rather than wax philosophical, let me just dump out some ideas: Start with Minix 3. It's a new microkernel, and it's meant for real use, unlike the original Minix. "This new OS is extremely small, with the part that runs in kernel mode under 4000 lines of executable code.&quo

Haskell or Erlang?

I've coded in both Erlang and Haskell. Erlang is practical, efficient, and useful. It's got a wonderful niche in the distributed world, and it has some real success stories such as CouchDB and Haskell is elegant and beautiful. It's been successful in various programming language competitions. I have some experience in both, but I'm thinking it's time to really commit to learning one of them on a professional level. They both have good books out now, and it's probably time I read one of those books cover to cover. My question is which? Back in 2000, Perl had established a real niche for systems administration, CGI, and text processing. The syntax wasn't exactly beautiful (unless you're into that sort of thing), but it was popular and mature. Python hadn't really become popular, nor did it really have a strong niche (at least as far as I could see). I went with Python because of its elegance, but since then, I've coded both p