In most cases we would assume correct parameters. For
example we will not convert an agrument to an integer
using parseInt() if an integer value is expected.

This reduces coding and IMO at time is much faster.

In other cases we normally check for missing arguments
etc.

The getItem error will be fixed in my next upload to
cvs.

PS. It is always good to mention a problem that you've
noticed in the API.

--
Raymond Irving


--- Leif W <[EMAIL PROTECTED]> wrote:
> I've noticed the same thing before but never
> mentioned it.  Most if not all
> functions I've seen assume correct parameters.  This
> was probably done for
> efficiency sake (I am guessing), so to save CPU time
> by having less code.
> But I was wondering if this makes it more difficult
> to track down errors in
> complex web apps.  Anyone else care to elaborate on
> the pros/cons of error
> checking in terms of execution time vs. code
> robustness and debugging?
> 
> Leif
> 
> ----- Original Message ----- 
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, September 05, 2003 10:43 PM
> Subject: Re: [Dynapi-Dev] Index out of bound in
> htmltextbox getItem
> 
> 
> >
> > I guess this is part of a larger design question.
> >
> > Should the Dynapi code check for invalid arguments
> to calls?
> >
> > Having the no property error error appear is
> functionally a thrown
> > error.
> >
> >
> >
> > > Not sure if I understand.  Is this a request to
> change something?  I'm
> not
> > > too familiar with this portion of the API, and
> not sure how this might
> > > affect other code, but see my proposed changes
> below (expanded for ease
> of
> > > readability).
> > >
> > > The line 99:
> > >
> > > if(typeof(index)=='number') return
> > > {text:o[index].text,value:o[index].value};
> > >
> > > Is proposed to be changed to something like
> this?
> > >
> > >  96 | p.getItem = function( index )
> > >  97 | {
> > >  98 |     if ( this.getElm() )
> > >  99 |     {
> > > 100 |         var o = this.elm.options;
> > > 101 |
> > > 102 |         if ( typeof( index ) == 'number'
> && ( index >= 0 || index
> <
> > > o.length)
> > > 103 |         {
> > > 104 |             return { text:o[index].text,
> value:o[index].value };
> > > 105 |         }
> > > 106 |         else if ( typeof( index ) ==
> 'undefined' )
> > > 107 |         {
> > > 108 |             return( null );
> > > 109 |         }
> > > 110 |         else
> > > 111 |         {
> > > 112 |             for( var i = 0; i < o.length;
> i++ )
> > > 113 |             {
> > > 114 |                 if ( index == o[i].value )
> > > 115 |                 {
> > > 116 |                     return {
> text:o[i].text, value:o[i].value };
> > > 117 |                 }
> > > 118 |             }
> > > 119 |         }
> > > 120 |     }
> > > 121 | };
> > >
> > > Leif
> > >
> > > ----- Original Message ----- 
> > > From: <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Friday, September 05, 2003 12:22 AM
> > > Subject: [Dynapi-Dev] Index out of bound in
> htmltextbox getItem
> > >
> > >
> > > >
> > > > What is the correct thing to do here?
> > > >
> > > > The simple thing would be to return null if
> o[index] is not a valid
> > > > option.
> > > >
> > > > Test choices:
> > > > if index < 0 || index >= o.length
> > > > o[index] === undefined
> > > >
> > > >
> > > >
> > > > Error: o[index] has no properties
> > > > Source File: dynapi3x/src/gui/htmllistbox.js
> > > > Line: 99
> > > >
> > > > 96 p.getItem = function(index){
> > > > 97 if(this.getElm()) {
> > > > 98 var o = this.elm.options;
> > > > 99 if(typeof(index)=='number') return
> > > {text:o[index].text,value:o[index].value};
> > > > else {
> > > > for(var i=0;i<o.length;i++)
> if(index==o[i].value) return {
> > > > text:o[i].text,
> > > > value:o[i].value
> > > > }
> > > > }
> > > > }
> > > > };
> > > >
> > > >
> > > >
>
-------------------------------------------------------
> > > > This sf.net email is sponsored by:ThinkGeek
> > > > Welcome to geek heaven.
> > > > http://thinkgeek.com/sf
> > > >
> _______________________________________________
> > > > Dynapi-Dev mailing list
> > > > [EMAIL PROTECTED]
> > > >
>
http://www.mail-archive.com/[EMAIL PROTECTED]/
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
>
-------------------------------------------------------
> > > This sf.net email is sponsored by:ThinkGeek
> > > Welcome to geek heaven.
> > > http://thinkgeek.com/sf
> > > _______________________________________________
> > > Dynapi-Dev mailing list
> > > [EMAIL PROTECTED]
> > >
>
http://www.mail-archive.com/[EMAIL PROTECTED]/
> > >
> >
> >
> >
>
-------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > Dynapi-Dev mailing list
> > [EMAIL PROTECTED]
> >
>
http://www.mail-archive.com/[EMAIL PROTECTED]/
> >
> 
> 
> 
> 
>
-------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dynapi-Dev mailing list
> [EMAIL PROTECTED]
>
http://www.mail-archive.com/[EMAIL PROTECTED]/


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://www.mail-archive.com/[EMAIL PROTECTED]/

Reply via email to