[whatwg] Progress Events "done" event

Why is 
	xhr.addEventListener("done", callCompleteHandler, false);
more concise than
	add_done_hook(xhr, cch)?
The former line is actually longer.

While English does not have loops, it has quantifiers and relations that are
quite convenient for most common purposes.  I do not think English with
loops would be cool.  C has loops but it is not cool at all.  It is
doubleplusuncool.  Declarative languages are, in general, cooler than
functional ones.  You need special languages for special purposes and there
is nothing weird about this fact.

Chris

-----Original Message-----
From: Garrett Smith [mailto:dhtmlkitchen@gmail.com] 
Sent: Monday, September 10, 2007 11:33 PM
To: K?i?tof ?elechovski
Cc: whatwg at whatwg.org; chaals at opera.com
Subject: Re: [whatwg] Progress Events "done" event

On 8/27/07, K?i?tof ?elechovski <giecrilj at stegny.2a.pl> wrote:
> Remember that JavaScript is a programming language after all.  You can use
a
> loop to get rid of the repetitions.
> Start from
> var done = ["load", "error", "abort"]...
> and apply the closure image.aEL(?, hPB, false) to it.
> Sincerely,
> Chris
>
That is true, in fact, it would also be possible to use Array.forEach
on that array.

The disadvantage is that it still invites code repetition. It is less
concise.

On the contrary:

xhr.addEventListener("done", callCompleteHandler, false);
function callCompleteHandler(e) {

}

Translates the use case to code quite naturally.


I like to make these examples that are conceptually similar:

"I'm going to call my friend and then I'm going to the dry cleaner."
vs.

"I'm going to call my friend and if she's not available, after that,
I'm going to the dry cleaner and if the call failed, after that, I'm
going to the dry cleaner, and if we talk for a bit, after that...

You get the point. English doesn't have loops or generators (hey
wouldn't that be cool!).

My point is that having a done event is more concise and makes
realizing the use-case requirement to code more explicit.

Garrett

> -----Original Message-----
> From: whatwg-bounces at lists.whatwg.org
> [mailto:whatwg-bounces at lists.whatwg.org] On Behalf Of Garrett Smith
> Sent: Sunday, August 26, 2007 8:25 AM
> To: whatwg at whatwg.org
> Cc: chaals at opera.com
> Subject: [whatwg] Progress Events "done" event
>
>
> ==========================================
> function showImage(imageHref) {
> ...
>
> // remove the progress bar when done.
>        image.addEventListener("load", hideProgressBar, false);
>        image.addEventListener("error", hideProgressBar, false);
>        image.addEventListener("abort", hideProgressBar, false);
> }
> ==========================================
>
> This is somewhat verbose. Clearly, the author is forced to repeat
> himself when all he really wants to do is hide the progress bar after
> the call is done.
>
>
>
>
>


-- 
Programming is a collaborative art.

Received on Tuesday, 11 September 2007 12:38:54 UTC