Comments on: eval() considered useful: code generation in JavaScript https://blog.berniesumption.com/software/eval-considered-useful/ Various writings on software development and photography Fri, 10 Aug 2018 08:19:11 +0000 hourly 1 https://wordpress.org/?v=4.9.11 By: Apostrophe OCD https://blog.berniesumption.com/software/eval-considered-useful/#comment-185 Sun, 20 May 2012 03:19:19 +0000 http://berniesumption.com/software/#comment-185 There you wrote about an old but classicle article introducing many useful optimixations though it is age is showing. Even eval() could not parse it.

]]>
By: Dave https://blog.berniesumption.com/software/eval-considered-useful/#comment-184 Fri, 17 Jun 2011 01:26:39 +0000 http://berniesumption.com/software/#comment-184 I only jumped on it because it was covered in a class I took once upon a time, and because in interviews I have been asked things like “what is the best way to debug….” I didn’t know – never made that mistake!

]]>
By: bernie https://blog.berniesumption.com/software/eval-considered-useful/#comment-183 Thu, 16 Jun 2011 23:01:58 +0000 http://berniesumption.com/software/#comment-183 Sure, I don’t literally ask “what is eval(), and why shouldn’t you use it”, the question is more likely to be “what does eval do”, followed by “what is it useful for”. Warning bells ring if I get an example that can be easily done without eval().

]]>
By: Dave https://blog.berniesumption.com/software/eval-considered-useful/#comment-182 Thu, 16 Jun 2011 20:39:48 +0000 http://berniesumption.com/software/#comment-182 “what is eval(), and why shouldn’t you use it” is a terrible question for an interview – it is counter-indicative, ie, a candidate who has used it extensively is more likely to know the answer than an candidate who read once that it is evil, found alternative methods, and forgot all about eval(). The second candidate is the better choice, but is unlikely to know the answer because they have never encountered the problem.

So, what is an example of a counter-indicative question, and why shouldn’t you use it?

]]>
By: Rick Renfrow https://blog.berniesumption.com/software/eval-considered-useful/#comment-181 Sat, 21 Jul 2007 07:05:26 +0000 http://berniesumption.com/software/#comment-181 I’ve written a very compact client-side HTML generation library (under 4k)… and it very heavily relies upon a single eval() statement to define hundreds of functions named after the HTML tag/attributes that they implement. It is very fast, and in benchmark tests, it beats both DOM and innerHTML methods of creating large constructs. In the website referenced, I’ve provided an online HTML() Construction Kit tool that allows you see how clientlets get rendered.

In the example, the 115 byte expression…

[[o=’O’,x=’X’,o].TD(),[x,x,x].TD(STYLE(background_color(‘red’))),[x,o,o].TD()].TR().TABLE(BORDER(1)+CELLPADDING(5))

…renders 255 bytes of flawless HTML…

<table border="1" cellpadding="5"><tr><td>O</td><td>X</td><td>O</td></tr><tr><td style=" background-color: red;">X</td><td style=" background-color: red;">X</td><td style=" background-color: red;">X</td></tr><tr><td>X</td><td>O</td><td>O</td></tr></table>

In fact, this library is the basis of a pop-up calendar (a date selector) implemented in well under 5k.

]]>
By: Tim https://blog.berniesumption.com/software/eval-considered-useful/#comment-180 Sat, 14 Apr 2007 14:20:08 +0000 http://berniesumption.com/software/#comment-180 Awww go ahead and sneak the laptop into the luggage… you gotta have somewhere to download the digital pics, you know… ;)

]]>
By: bernie https://blog.berniesumption.com/software/eval-considered-useful/#comment-179 Thu, 12 Apr 2007 12:16:03 +0000 http://berniesumption.com/software/#comment-179 Indeed. If the data set is large enough, one could present standard deviations, or some more user friendly measure of variance, to indicate if an operation is generally fast but seems to really kill some browsers / configurations.

I had another look at TWiki, it looks suitable for creating a site where people can submit code into a standard test suite, but not suitable for collecting the results from visitors. We’d probably need a custom web app for that.

I am looking for an excuse to learn Ruby on Rails, but there’s so little time…

The next big block of time I have free is my Honeymoon in 3 months, and I’d be dead for even suggesting that I bring the laptop ;o)

]]>
By: Tim https://blog.berniesumption.com/software/eval-considered-useful/#comment-178 Thu, 12 Apr 2007 11:43:07 +0000 http://berniesumption.com/software/#comment-178 It would be challenging to account for the variables, like cpu speed, memory size, etc. Easier to account for the browser being used… But if you got enough people to do it, in the end statistics would win out and you could derive a statistically valid cost of specific operations… in the end you wouldn’t be able to say “this is the cost to YOU for this operation,” but you -would- be able to say “this is the relative cost of these two operations, and if you use the faster of the two, on average your site will perform better for all visitors.” THAT would be cool, and in fact much more valuable…

]]>
By: bernie https://blog.berniesumption.com/software/eval-considered-useful/#comment-177 Mon, 09 Apr 2007 10:07:36 +0000 http://berniesumption.com/software/#comment-177 That’s perfect because the tests are posted as HTML, and run automatically.

Now imagine anyone coming to that page, running the tests, and the results being posted back to the server for collating.

You’d run it on a domain with no cookies or login, so there’s nothing for the scripts to steal if someone posts malicious code.

]]>
By: Tim https://blog.berniesumption.com/software/eval-considered-useful/#comment-176 Sat, 07 Apr 2007 14:46:24 +0000 http://berniesumption.com/software/#comment-176 Here’s one attempt at benchmarking various Javascript primitives… http://www.jorendorff.com/articles/javascript/speed-test.html

]]>