Node is not optimized for "newcomers are not surprised."  That's an
occasional side effect of what it IS optimized for: "javascript
programmers can do a lot easily".

You spend very little time as a newcomer.  You spend a lot more time
in the state of "I know how X and Y work, and so expect Z to behave
the same."  It's more important for APIs to be consistent than
immediately intelligible to someone who has never seen them before.

There are several cases where we do `var thing =
module.createThing(args, someEventHandler)`.

var request = http.get(options, function (response) { })
// vs
var request = http.get(options).on('response', function (response) { })

var watcher = fs.watch(filename, function (change) { })
// vs
var watcher = fs.watch(filename).on('change', function (change) {  })

Almost every EventEmitter subclass in node core has some factor
creator that lets you attach a listener to its most relevant event
when creating it.  This is a very consistent pattern.  Creating a
server or request is not a one-off "I have a question, give me an
answer".  It's a long-lived object.  fs.exists(cb) violates the
pattern because it is a one-off question, but does not take an error
argument.  Furthermore, the failure of stat does not necessarily mean
that the file doesn't exist, so it's also

The only time we don't do this, actually, is when the object doesn't
have a single clear event that you care about.   For example, with
child_process.spawn, there are several events that you might be
interested in, and so we don't add the sugar API to add an event
listener at creation time.

Making things needlessly verbose may make newcomers spend a few
minutes less reading documentation the first time, but they'll make us
all spend a few minutes more every time for the rest of our lives.

That's not a good trade.

That's not to say that we don't care about the newcomer experience, of
course.  But when designing APIs, it's important not to skew your
least-surprise too far in the direction of never surprising anyone
ever.  Newcomers will be surprised by many reasonable things.  The
litmus test is if it surprises someone who is familiar with the rest
of the Node.js API.  That is how we evolve these things in context.


On Thu, May 31, 2012 at 4:06 PM, Mark Hahn <[email protected]> wrote:
>>  One can argue that the macro of having http.createServer(f) be
>> http.createServer().on("request", f) is confusing
>
> They are both confusing to a newbie.  But one of them presents reality and
> starts the newbie on the road to understanding.  The other is undocumented
> magic that causes more confusion.
>
> What better time to introduce events?
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to