News for hackers. Stuff that matters.
Re:Is eval evil? Just-in-time compiling by chrisseaton on Monday November 19, 2018 @12:29PM (#18487988)
Contrary to what the article says, there is no reason whatsoever that code in an eval, even if it uses the calling environment, cannot be optimised.

I work on a Ruby implementation that optimises through eval just fine.

Re:Is eval evil? Just-in-time compiling by zamalek on Monday November 19, 2018 @02:20PM (#18488903)
Exactly. It's just like SQL: different queries end up as different entries in the query cache; although SQL is beneficially fuzzy in this case, if only the constants differ you should get a cache hit.

The "safe" and fast way to use eval for JIT is to get it to return a function, with all user inputs as parameters (like like the safe and fast way to do SQL is with parameters):

    var f = eval("(function (a, b) { return a + b })");
    f("a", "b");
Re:Is eval evil? Just-in-time compiling by wefarrell on Monday November 19, 2018 @03:56PM (#18489694)
Why not just do:

var f = new Function('a', 'b', 'return a + b')

Re:Is eval evil? Just-in-time compiling by zamalek on Monday November 19, 2018 @06:06PM (#18490539)
I had no idea that was possible. The concept still applies though.