Hi Peter,

Am 16.12.2009 um 15:03 schrieb Peter Schneider:

[...] Wouldn't "Function" be the better choice?

Why would it? There doesn't seem to be a real difference to me (except
regarding scoping, but this should be irrelevant here).

I think it's a bit more than just scoping. As far as I remember the eval() call
starts a complete new compiler, parser etc. pp.

I fail to see how creating a Function object based on a string is different?

On the other hand it seems to me that "eval() is evil" is common sense
throughout all developers ;)

Why do you consider feeding a string to the Function constructor less evil?

I've tried the following replacement in our application that works
quite good
(and is about 6 to 7 times faster!):

Let me guess: You have Firebug enabled, right? As mentioned on this
list a short while ago, Firebug can _severely_ affect JavaScript
performance.

Yes, and no.
I've done my measurements with several Browsers and most of them do not even
have a Firebug (Opera, IE, Chrome, Safari).

Do you have a test page that you could share with us? I just created a mini test page myself (see attachment), and eval() was as fast or even faster than Function() (especially in Safari where, for whatever reason, the Function() variant is really slow).

I agree, that performance is nothing easy to measure. And by the way, that was
not my main concern (just a spin-off ;) )

In this case, performance _is_ my main concern because I still don't see any other significant difference. Again, why do you think the Function() way is any cleaner than eval()? Both take a string and compile and execute it on the fly.

For some more performance tests, take a look at this page:

http://weblogs.asp.net/yuanjian/archive/2009/03/22/json-performance-comparison-of-eval-new-function-and-json.aspx

The Function approach takes about the same time as the eval() call
(with the exception of the Safari 4 beta where it's way slower - but I
guess this is fixed in the current Safari version).

Please note that the results for Firefox in the first two tables seem
to indicate that Function() is way faster - but if you scroll down,
there is another table with Firebug turned off, and the results are
quite different!

As mentioned, performance was not the main focus. I just followed the
"eval() is evil" prayers... ;)

If you look closer, you'll see that Function() with a string is just as frowned upon. eval() is used in qooxdoo because there wasn't any usable alternative until recently (and there's already an open bug for making use of the new native JSON implementations).

As with most of the JavaScripts engine features, it seems to be that the performance issue of eval() is decreasing with every new browser version.

I don't have this impression. Do you have any tests/references for this assumption?

My main intention was to 'clean' my code so that most tools (e.g. jslint[1] or
even qooxdoos own "lint") will not complain anymore.

If the tools complain about eval() but not about Function() with a string, the tools are broken :-)

I will not start to list all the many "eval() is evil" pages around that google spits out when you ask 'em. But as far as I know it's still better, not to use
eval()[2].

I agree that eval() should only be used when necessary. But your proposed replacement is just as evil (and slower, according to my measurements).

Regards,

  Andreas J.


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to