Though Errors definitely have their place, such as when an error
occurs, using an error for regular return codes during expected events
(assuming this function expects the look up to fail some times) is a
bit overkill, and horrible for performance.

http://jsperf.com/a-string-is-not-an-error


On Mar 9, 10:36 am, Roly Fentanes <[email protected]> wrote:
> btw http://www.devthought.com/2011/12/22/a-string-is-not-an-error/
>
>
>
>
>
>
>
> On Friday, March 9, 2012 3:30:49 AM UTC-7, Angelo Chen wrote:
>
> > Hi,
>
> > Struggling to change coding practice, following has two samples, which
> > one is correct? or any other approaches available?
>
> > exports.get_user = function (id, func) {
> >         var found = false
> >         for (var i = 0; i < users.length; i ++) {
> >                 if (users[i].id === id) {
> >                         found = true
> >                         func(null, users[i])
> >                         break;
> >                 }
> >         }
> >         if (!found)
> >                         func("NOT_FOUND", null)
> > }
>
> > exports.get_user = function (id, func) {
> >         for (var i = 0; i < users.length; i ++) {
> >                 if (users[i].id === id) {
> >                         func(null, users[i])
> >                         break;
> >                 }
> >                 if (i == users.length)
> >                         func("NOT_FOUND", null)
> >         }
> > }

-- 
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