On 02/16/2011 03:06 PM, Jerome Velociter wrote:

[snip]

>
>     I prefer to use native JavaScript APIs whenever possible and use
>     Prototype only when:
>     * it simplifies my code
>     * it fixes a cross browser issue.
>
>     You can make a proposal but I'd be -0 for using Prototype in any
>     situation.
>
>
>
> I'm curious to know the rationale behind your reasoning.
>
> I see mostly advantages in preferring prototype over native APIs :
>
> * Browser issues can be tricky, I personally would not assume that I
> always know when to use prototype to avoid one. I admit I don't test my
> code in all browsers (Konqueror, Opera, etc. you name it.), but I know
> prototype.js is extensively tested including in exotic browsers.
>
> * Using prototype.js selectors you should get the best of breed of
> browsers selectors, so overall the performance is better. When you use
> getElementsByTagName I guess you assume it runs faster than prototype
> selector. Maybe it's true today (but I would think not by far) but I
> will pretty likely not be tomorrow (and let's hope by far) - when most
> browsers will have a good implementation of querySelectorAll (like Opera
> has for example) ; which prototype selector will certainly rely on (when
> it's available) in future versions (if not already, haven't checked).
> The advantage of using prototype.js here is the same argument of having
> a unified API and hiding implementation details. Native JS APIs is
> unfortunately always a moving target, since browsers implement
> specifications at their own pace, not in the same order, etc. Only a
> using a library's API you can abstract this and be pretty safe your code
> will run fine everywhere and with maximized performance.
>
> * Where do you place the bar ? Why $('element') simplifies your code
> over .getElementById('element') but not .select('img') over
> .getElementsByTagName('img')
>
> * RE my argument about not extended elements
>
> I won't make a proposal to enforce that, but again I'm curious to hear
> what you think.

I guess my first reason is that I know the native API better than the 
Prototype one so it's natural that I tend to use the former. When I'm 
pretty sure that a native function/property works fine cross-browser 
(because I've used it many time in the past) I don't spend time looking 
for an alternative in the Prototype documentation. That's why I use 
parentNode rather than up() and firstChild rather than down() even if 
they are longer.

Then I know that more code means more bugs, so even if Prototype is 
tested extensively it can have bugs which means that when something is 
not working as expected in my code (using Prototype) I have to check 
their code also before blaming the browser.

Regarding performance, I don't think Prototype can ever beat the native 
API since it is relying on it. I'm pretty sure that browsers that 
implement querySelectorAll use it internally for getElementsByTagName.

Thanks,
Marius

>
> Jerome.

[snip]
_______________________________________________
devs mailing list
devs@xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to