Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Callback Style Preference
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 41 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Daniel Rinehart  
View profile  
 More options May 29 2012, 9:24 pm
From: Daniel Rinehart <dani...@neophi.com>
Date: Tue, 29 May 2012 21:24:06 -0400
Local: Tues, May 29 2012 9:24 pm
Subject: Callback Style Preference
Is there consensus on the value to pass to a callback if there isn't
an error and there may or may not be a resulting value. A quick survey
of node.js code along with popular modules seems to indicate that null
is most common but undefined and false also pop up frequently. While
any falsey value works I was curious if one was preferred.

-- Daniel R. <dani...@neophi.com> [http://danielr.neophi.com/]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mariusz Nowak  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 5:05 am
From: Mariusz Nowak <mari...@medikoo.com>
Date: Wed, 30 May 2012 02:05:06 -0700 (PDT)
Local: Wed, May 30 2012 5:05 am
Subject: Re: Callback Style Preference

It should be null or undefined only, everything else is a value, and can
mistakenly accepted as an error.

There are however asynchronous functions that never resolve with an error
(e.g. path.exists) and as there's no point in always sending null to their
callbacks, they're designed to pass success value as first argument (in
case of path.exists true or false).

--
Mariusz Nowak - @medikoo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Caswell  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 10:37 am
From: Tim Caswell <t...@creationix.com>
Date: Wed, 30 May 2012 09:37:29 -0500
Local: Wed, May 30 2012 10:37 am
Subject: Re: [nodejs] Re: Callback Style Preference

The most correct value for the error parameter is "undefined", but most of
us are lazy and type "null" instead.  In most code it expects the err
parameter to be either falsy or an Error instance, so it doesn't matter if
you use false, undefined, null, 0, or even "".

While there are some functions that never emit an error, if there is any
chance they would emit one in the future, save yourself the trouble and
reserve the err parameter.  Also it makes the function work with
flow-control tools and wrappers that assume the pattern.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Isaac Schlueter  
View profile  
 More options May 30 2012, 12:22 pm
From: Isaac Schlueter <i...@izs.me>
Date: Wed, 30 May 2012 09:22:42 -0700
Local: Wed, May 30 2012 12:22 pm
Subject: Re: [nodejs] Re: Callback Style Preference
path.exists (moved to fs.exists) is an abomination for so many
reasons.  We can't get rid of it, because it's too widely used, but
it's really pretty awful.  It predates the cb(er, data) pattern in
node, and is one of the very few exceptions to it.

Any time you find yourself using it, you should try to figure out what
you're really trying to find out, and use some other fs call instead.
Usually the best approach is to just try to do what you're going to
do, and handle the error.  If you're using a file's existence as a
lock of some sort, it's better to open the file in O_EXCL mode
instead.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Rogers  
View profile  
 More options May 30 2012, 6:11 pm
From: Marco Rogers <marco.rog...@gmail.com>
Date: Wed, 30 May 2012 15:11:29 -0700 (PDT)
Local: Wed, May 30 2012 6:11 pm
Subject: Re: [nodejs] Re: Callback Style Preference

I don't know why we can't change it. Sure it may break a lot of working
code. But as you've outlined, replacing it with more preferable methods is
fairly straight forward. It's even easily shimmable for folks who don't
want to upgrade. We're talking about breaking nextTick but "can't" get rid
of this? Doesn't seem logical.

:Marco


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 6:45 pm
From: Mark Hahn <m...@hahnca.com>
Date: Wed, 30 May 2012 15:45:53 -0700
Local: Wed, May 30 2012 6:45 pm
Subject: Re: [nodejs] Re: Callback Style Preference

I would be very unhappy if someone broke my code.  Ask the jquery bdfl what
happened when he tried to make a non-backwards-compatible change.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Rogers  
View profile  
 More options May 30 2012, 7:49 pm
From: Marco Rogers <marco.rog...@gmail.com>
Date: Wed, 30 May 2012 16:49:36 -0700 (PDT)
Local: Wed, May 30 2012 7:49 pm
Subject: Re: [nodejs] Re: Callback Style Preference

If you're using a pre-1.0 platform, your code is subject to breakage. Also
you have to opt into upgrading and every major node update has required
minor changes.

At some point we went from changing the node api a lot to make it better to
not changing it at all for fear of crying developers. I'm not suggesting we
open flood gates. I'm suggesting we continue to refine the api and get as
close to one with no unnecessary warts as we can before going 1.0. Because
then we really are screwed.

:Marco


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 8:11 pm
From: Mark Hahn <m...@hahnca.com>
Date: Wed, 30 May 2012 17:11:10 -0700
Local: Wed, May 30 2012 8:11 pm
Subject: Re: [nodejs] Re: Callback Style Preference

The ver 1.0 moniker is pretty much meaningless.  Many many people have it
in production.

On Wed, May 30, 2012 at 4:49 PM, Marco Rogers <marco.rog...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 8:11 pm
From: Mark Hahn <m...@hahnca.com>
Date: Wed, 30 May 2012 17:11:37 -0700
Local: Wed, May 30 2012 8:11 pm
Subject: Re: [nodejs] Re: Callback Style Preference

It's like google's "beta" gmail was.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Rogers  
View profile  
 More options May 30 2012, 8:47 pm
From: Marco Rogers <marco.rog...@gmail.com>
Date: Wed, 30 May 2012 17:47:08 -0700 (PDT)
Local: Wed, May 30 2012 8:47 pm
Subject: Re: [nodejs] Re: Callback Style Preference

Yes I know that. But that is despite the pre-1.0 version. Node has tried to
be very strict about what he version means from the beginning. pre-1.0
means "stable, but not done". Some people think "stable" means "we won't
break backwards compat". But I'm suggesting that it actually mean "we'll
try really hard for backwards compat, but we might break things for the
good of the api". I think in the case of path.exists, this is very doable.
If we can't do stuff like this now, then we are resigning ourselves to
being stuck with these warts forever. And path.exists/fs.exists is a
particular bad wart because it's the exact place people will look for this
functionality. So the propagation of this will continue to go up.

:Marco


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 10:42 pm
From: Mark Hahn <m...@hahnca.com>
Date: Wed, 30 May 2012 19:42:02 -0700
Local: Wed, May 30 2012 10:42 pm
Subject: Re: [nodejs] Re: Callback Style Preference

I understand.  I'm just being contrary.

>   Node has tried to be very strict about what he version means from the

beginning. pre-1.0 means "stable, but not done".

God forbid it should ever be "done", whatever that means.   I doubt there
will be much difference between v 0.999 and v 1.001.

On a more serious note, what harm does .exists do?  http.createServer
violates all the rules and it is the first thing a node newbie sees.

On Wed, May 30, 2012 at 5:47 PM, Marco Rogers <marco.rog...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
P. Douglas Reeder  
View profile  
 More options May 31 2012, 1:21 pm
From: "P. Douglas Reeder" <reeder...@gmail.com>
Date: Thu, 31 May 2012 10:21:07 -0700 (PDT)
Local: Thurs, May 31 2012 1:21 pm
Subject: Re: [nodejs] Re: Callback Style Preference

FWIW, I found path.exists() to be odd when I was first learning Node, and didn't understand how things worked.

Given that there's a straightforward replacement, I see no reason it can't be removed as part of a major update.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Rogers  
View profile  
 More options May 31 2012, 2:08 pm
From: Marco Rogers <marco.rog...@gmail.com>
Date: Thu, 31 May 2012 11:08:33 -0700 (PDT)
Local: Thurs, May 31 2012 2:08 pm
Subject: Re: [nodejs] Re: Callback Style Preference

> On a more serious note, what harm does .exists do?  http.createServer
> violates all the rules and it is the first thing a node newbie sees.

Curious. What rules you think createServer violates?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mariusz Nowak  
View profile   Translate to Translated (View Original)
 More options May 31 2012, 2:12 pm
From: Mariusz Nowak <mari...@medikoo.com>
Date: Thu, 31 May 2012 11:12:06 -0700 (PDT)
Local: Thurs, May 31 2012 2:12 pm
Subject: Re: [nodejs] Re: Callback Style Preference

+1

I looked at the Node's source, and indeed path.exists (to be fs.exists) is
just wrapper over fs.stat.

If there's no "lighter" way for checking whether path exists, indeed it's
best it it's not in the API at all. There are already two good reasons for
that: it encourages bad practices and it's asynchronous function that
doesn't follow convention.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oliver Leics  
View profile  
 More options May 31 2012, 3:08 pm
From: Oliver Leics <oliver.le...@gmail.com>
Date: Thu, 31 May 2012 21:08:03 +0200
Local: Thurs, May 31 2012 3:08 pm
Subject: Re: [nodejs] Re: Callback Style Preference

On Thu, May 31, 2012 at 8:08 PM, Marco Rogers <marco.rog...@gmail.com> wrote:

>> On a more serious note, what harm does .exists do?  http.createServer
>> violates all the rules and it is the first thing a node newbie sees.

> Curious. What rules you think createServer violates?

The callback gets no error argument as the first argument.

I would rigorously throw away _all_ of those inconsistencies right
now, but at least with 0.8. For me, the leading zero in a
version-number means: Expect changes, anytime, everywhere.

Nobody could foresee that it is generally best practice to always
reserve the first argument of an callback for error-objects, no matter
if the function checks for file-existence or if it creates a
http-server. But everyone decided to run node.js in production before
the first major release, version 1.0.0. Everyone should know about
that and don't wine if anything breaks.

Change it before 1. But I doubt that this will happen.

BTW: That google-mail 'beta' label was pure marketing.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mariusz Nowak  
View profile  
 More options May 31 2012, 3:15 pm
From: Mariusz Nowak <mari...@medikoo.com>
Date: Thu, 31 May 2012 12:15:32 -0700 (PDT)
Local: Thurs, May 31 2012 3:15 pm
Subject: Re: [nodejs] Re: Callback Style Preference

@Oliver createServer is not asynchronous function, it is synchronous
function that returns event emitter and optionally accepts listener. It's
different concept/pattern and all rules are followed


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oliver Leics  
View profile  
 More options May 31 2012, 3:22 pm
From: Oliver Leics <oliver.le...@gmail.com>
Date: Thu, 31 May 2012 21:22:05 +0200
Local: Thurs, May 31 2012 3:22 pm
Subject: Re: [nodejs] Re: Callback Style Preference

On Thu, May 31, 2012 at 9:15 PM, Mariusz Nowak <mari...@medikoo.com> wrote:
> @Oliver createServer is not asynchronous function, it is synchronous
> function that returns event emitter and optionally accepts listener. It's
> different concept/pattern and all rules are followed

I know that, but the missing error parameter for the callback is still
an inconsistency (even if there are very very rare till zero cases
that actually give an error-object on req-res connection level)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mariusz Nowak  
View profile  
 More options May 31 2012, 3:26 pm
From: Mariusz Nowak <mari...@medikoo.com>
Date: Thu, 31 May 2012 12:26:22 -0700 (PDT)
Local: Thurs, May 31 2012 3:26 pm
Subject: Re: [nodejs] Re: Callback Style Preference

@Oliver Synchronous functions throw errors if there's any, they do not take
any callback for that.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oliver Leics  
View profile  
 More options May 31 2012, 3:39 pm
From: Oliver Leics <oliver.le...@gmail.com>
Date: Thu, 31 May 2012 21:39:17 +0200
Local: Thurs, May 31 2012 3:39 pm
Subject: Re: [nodejs] Re: Callback Style Preference

On Thu, May 31, 2012 at 9:26 PM, Mariusz Nowak <mari...@medikoo.com> wrote:
> @Oliver Synchronous functions throw errors if there's any, they do not take
> any callback for that.

You can repeat that "it's a synchronous function" argument as long as
you want, for me it is an inconsistency that the callback of
http.createServer gets no error argument (even if rarely or never
used)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oliver Leics  
View profile  
 More options May 31 2012, 3:41 pm
From: Oliver Leics <oliver.le...@gmail.com>
Date: Thu, 31 May 2012 21:41:31 +0200
Local: Thurs, May 31 2012 3:41 pm
Subject: Re: [nodejs] Re: Callback Style Preference
BTW: http.createServer should/must continue to emit the error event.
That's very consistent.

On Thu, May 31, 2012 at 9:39 PM, Oliver Leics <oliver.le...@gmail.com> wrote:
> On Thu, May 31, 2012 at 9:26 PM, Mariusz Nowak <mari...@medikoo.com> wrote:
>> @Oliver Synchronous functions throw errors if there's any, they do not take
>> any callback for that.

> You can repeat that "it's a synchronous function" argument as long as
> you want, for me it is an inconsistency that the callback of
> http.createServer gets no error argument (even if rarely or never
> used)

--
Oliver Leics @ G+
https://plus.google.com/112912441146721682527

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott González  
View profile  
 More options May 31 2012, 3:44 pm
From: Scott González <scott.gonza...@gmail.com>
Date: Thu, 31 May 2012 15:44:44 -0400
Local: Thurs, May 31 2012 3:44 pm
Subject: Re: [nodejs] Re: Callback Style Preference

On Thu, May 31, 2012 at 3:39 PM, Oliver Leics <oliver.le...@gmail.com>wrote:

> You can repeat that "it's a synchronous function" argument as long as
> you want, for me it is an inconsistency that the callback of
> http.createServer gets no error argument (even if rarely or never
> used)

The point is that it's not a callback. It's a shortcut for adding a request
event listener.

https://github.com/joyent/node/blob/f721d02c8a356c1a9a40d8bf709918674...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oliver Leics  
View profile  
 More options May 31 2012, 3:52 pm
From: Oliver Leics <oliver.le...@gmail.com>
Date: Thu, 31 May 2012 21:52:25 +0200
Local: Thurs, May 31 2012 3:52 pm
Subject: Re: [nodejs] Re: Callback Style Preference
On Thu, May 31, 2012 at 9:44 PM, Scott González

<scott.gonza...@gmail.com> wrote:
> On Thu, May 31, 2012 at 3:39 PM, Oliver Leics <oliver.le...@gmail.com>
> wrote:

>> You can repeat that "it's a synchronous function" argument as long as
>> you want, for me it is an inconsistency that the callback of
>> http.createServer gets no error argument (even if rarely or never
>> used)

> The point is that it's not a callback. It's a shortcut for adding a request
> event listener.

Yes, I know that too. And you might have already guessed it: It's just
another inconsistency that confuses ppl ;-)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile  
 More options May 31 2012, 4:17 pm
From: Mark Hahn <m...@hahnca.com>
Date: Thu, 31 May 2012 13:17:43 -0700
Local: Thurs, May 31 2012 4:17 pm
Subject: Re: [nodejs] Re: Callback Style Preference

>  The point is that it's not a callback. It's a shortcut for adding a

request event listener.

And that is not a common thing in node.  It is just there to make the code
sample on the front page look good.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Hahn  
View profile  
 More options May 31 2012, 4:18 pm
From: Mark Hahn <m...@hahnca.com>
Date: Thu, 31 May 2012 13:18:51 -0700
Local: Thurs, May 31 2012 4:18 pm
Subject: Re: [nodejs] Re: Callback Style Preference

>   It is just there to make the code sample on the front page look good.

Which confused me to no end when I first studied node.  I'm sure it
confuses many others.  It is a bit of "magic" and magic is not a good thing.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jake Verbaten  
View profile  
 More options May 31 2012, 6:44 pm
From: Jake Verbaten <rayn...@gmail.com>
Date: Thu, 31 May 2012 23:44:35 +0100
Local: Thurs, May 31 2012 6:44 pm
Subject: Re: [nodejs] Re: Callback Style Preference

> Yes, I know that too. And you might have already guessed it: It's just
> another inconsistency that confuses ppl ;-)

It's not inconsistent. The server is an event emitter the error handling
pattern is server.on("error", errorHandler). There are two error handling
patterns.

The other error handling pattern of (err, data) is for asynchronous
operations that are not event emitters.

One can argue that the macro of having http.createServer(f) be
http.createServer().on("request", f) is confusing


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 41   Newer >
« Back to Discussions « Newer topic     Older topic »