[dojo-contributors] Prototype-al simplicity

Bill Keese bill at dojotoolkit.org
Fri Apr 7 21:46:42 EDT 2006


>> IIRC some of that weird case handling is there for a reason, but yeah, that
>> would be another good place to start.

Yup, I was indirectly challenging you to tell me what the reason was. :-)

Part of the error checking in that function is to give an error message 
if the function is used on a browser we don't support.  I'd rather just 
say "the function's results are unpredictable"  (as opposed to "it won't 
work, but at least will give you a pretty error message")**

The other error checking is for user error (passing a null node). 
Doesn't seem worth it either, but maybe I'm wrong.

And what's the string thing?
	var cs = new String(classStr);

** this brings up a related question about which browsers we support, 
and whether the code size would reduce greatly by limiting that list. 
The current list (from http://dojo.jot.com/FAQ#Supported%20Browsers) is:

- Latest Safari (2.0.x today).
- Latest Opera (8.5 today, 9.0 soon)
- IE 5.5+
- Firefox 1.0+
- Latest Konqueror (3.5 today)

Note that although we say we support IE5.5, it doesn't actually work. 
I'm also suspicious about Opera; I know I'm not testing it, and usually 
things that aren't tested don't work.

Bill

Scott J. Miles wrote:
> Yes, there are frequently situations were 'weird cases' are there for a
> specific reason, so we have to be really careful.
>  
> But in Bill's particular example, the return value stuff and error exception
> seems unusual, and I agree that there is a lot of removable cruft like that.
>  
> Maybe this is too specific for this conversation, but in general we don't
> have rules regarding error checking. Most of the style.js functions don't
> test for bad node input. Obviously some do. I suspect we need some
> standardization.
>  
>>> And in some cases (when the calling code needs both width and height),
> performance will probably improve.
> 
> Sure, but the converse is also true. 
> 
> Regards,
> Scott J. Miles
> TurboAjax Group
> http://www.turboajax.com
>  
> ________________________________
> 
> From: dojo-contributors-bounces at dojotoolkit.org
> [mailto:dojo-contributors-bounces at dojotoolkit.org] On Behalf Of Tom Trenka
> Sent: Friday, April 07, 2006 10:40 AM
> To: dojo dev.
> Subject: Re: [dojo-contributors] Prototype-al simplicity
> 
> 
> IIRC some of that weird case handling is there for a reason, but yeah, that
> would be another good place to start.
> 
> 
> On 4/7/06, Bill Keese < bill at dojotoolkit.org <mailto:bill at dojotoolkit.org> >
> wrote: 
> 
> 	Tom Trenka wrote:
> 	> For instance, instead of: 
> 	>
> 	>     getViewportWidth
> 	>     getViewportHeight
> 	>
> 	> ...we'd have this:
> 	>
> 	> object getViewportSize
> 	>
> 	> ...where the return object would look like:
> 	> { width:..., height:... } 
> 	
> 	That probably makes sense.  And in some cases (when the calling code
> 	needs both width and height), performance will probably improve.
> 	
> 	A few other things:
> 	  - lots of deprecated functions that can be removed 
> 	
> 	  - coordinates are handled both as an array [5,7] and an object {w:
> 5,
> 	h: 7}.  Just an object should be sufficient.
> 	
> 	
> 	Just in general I would take error checking and weird case handling
> out
> 	of functions.  For example, here is a current setClass() function: 
> 	
> 	dojo.html.setClass = function(node, classStr){
> 	        node = dojo.byId(node);
> 	        if(!node){ return false; }
> 	        var cs = new String(classStr);
> 	        try{
> 	                if(typeof node.className == "string"){
> 	                        node.className = cs;
> 	                }else if(node.setAttribute){
> 	                        node.setAttribute("class", classStr);
> 	                         node.className = cs;
> 	                }else{
> 	                        return false;
> 	                }
> 	        }catch(e){
> 	                dojo.debug("dojo.html.setClass() failed", e);
> 	        }
> 	        return true;
> 	}
> 	
> 	I'm tempted to rewrite it as below:
> 	
> 	dojo.html.setClass = function(node, classStr){
> 	        node = dojo.byId(node);
> 	        if(typeof node.className == "string"){
> 	                node.className = cs;
> 	        }else{
> 	                node.setAttribute("class", classStr);
> 	        }
> 	}
> 

-- 

Bill



More information about the dojo-contributors mailing list