From: <ml...@id...> - 2003-09-06 02:44:01
|
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: <ml...@id...> > To: <dyn...@li...> > 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 > > Dyn...@li... > > http://www.mail-archive.com/dyn...@li.../ > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dynapi-Dev mailing list > Dyn...@li... > http://www.mail-archive.com/dyn...@li.../ > |
From: Leif W <war...@us...> - 2003-09-06 14:24:40
|
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: <ml...@id...> To: <dyn...@li...> 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: <ml...@id...> > > To: <dyn...@li...> > > 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 > > > Dyn...@li... > > > http://www.mail-archive.com/dyn...@li.../ > > > > > > > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > Dynapi-Dev mailing list > > Dyn...@li... > > http://www.mail-archive.com/dyn...@li.../ > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dynapi-Dev mailing list > Dyn...@li... > http://www.mail-archive.com/dyn...@li.../ > |
From: Raymond I. <xw...@ya...> - 2003-09-07 13:42:33
|
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 <war...@us...> 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: <ml...@id...> > To: <dyn...@li...> > 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: <ml...@id...> > > > To: <dyn...@li...> > > > 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 > > > > Dyn...@li... > > > > > http://www.mail-archive.com/dyn...@li.../ > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This sf.net email is sponsored by:ThinkGeek > > > Welcome to geek heaven. > > > http://thinkgeek.com/sf > > > _______________________________________________ > > > Dynapi-Dev mailing list > > > Dyn...@li... > > > > http://www.mail-archive.com/dyn...@li.../ > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > Dynapi-Dev mailing list > > Dyn...@li... > > > http://www.mail-archive.com/dyn...@li.../ > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dynapi-Dev mailing list > Dyn...@li... > http://www.mail-archive.com/dyn...@li.../ __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com |