Poll on Eval in Ruby

I am Lisp programmer and I write an article on
issues as macros, fexprs and eval. I want to
compare opinion of Ruby and Lisp programmers on eval.
Some readers might think that such post constitute
spam on Ruby newsgroup, but I believe that resulting
information will not be completely devoid of value

  • even for Ruby community.

If you want to contribute few seconds, the poll is
on my blog, on the top of the right column.

http://kazimirmajorinc.blogspot.com

Thanks,

On 9.10.2009 18:43, David M. wrote:

So… I avoid languages that don’t have eval. But I avoid using eval in the
languages I use. Does that make sense?

It has, David. I think it is, lets say,
developed form of “useful but overused”
opinion.

On Thursday 08 October 2009 08:15:06 am Kazimir Majorinc wrote:

I want to
compare opinion of Ruby and Lisp programmers on eval.

If you want to contribute few seconds, the poll is
on my blog, on the top of the right column.

http://kazimirmajorinc.blogspot.com

There wasn’t an option for “Absolutely essential for the one time out of
a
billion you actually need it. Otherwise, avoid it entirely.”

I can’t remember the last time I used eval directly in Ruby, and I’ve
seen it
maybe once or twice in library code. I’ve also seen it abused by people
who
really should know better. 90% of the time you find yourself reaching
for eval,
you’re Doing It Wrong. Another 9% of the time, you’re working around a
missing
language feature, and it’d be better to fix that feature, or at least
bury your
use of eval deep in a library.

But there was the time I used Javascript on HD-DVD, which had many
limitations, including not having eval. And many of its other
limitations
could’ve been worked around if there had been an eval. A simple example:
Downloading and executing code was complex and often disruptive – eval
would’ve made it trivial.

So… I avoid languages that don’t have eval. But I avoid using eval in
the
languages I use. Does that make sense?

On Friday 09 October 2009 01:10:07 pm Kazimir Majorinc wrote:

On 9.10.2009 18:43, David M. wrote:

So… I avoid languages that don’t have eval. But I avoid using eval in
the languages I use. Does that make sense?

It has, David. I think it is, lets say,
developed form of “useful but overused”
opinion.

Well, except that I’m not making any statement about how people use it,
because I don’t know. The few examples I’ve found don’t point to any
sort of
systemic overuse – if there’s a language feature, someone has found a
way to
abuse it.

If you want to contribute few seconds, the poll is
on my blog, on the top of the right column.

Are we talking about

a = 'foo'
b = 'a + "bar"'
eval "'yummy ' + #{b} * 2"

or about

class A
    def initialize
        @x = "foo"
    end
end

A.new.instance_eval {@x}

On Sat, Oct 10, 2009 at 7:10 AM, lith [email protected] wrote:

class A
def initialize
@x = “foo”
end
end

A.new.instance_eval {@x}

I thought we were talking about all eval version (eval, instance_eval,
class_eval, etc) so I answered the one that was “has it’s place” or
something like that.

If we are talking exclusively about pure eval, I agree with David, I
almost never use it.

Jesus.

Hi –

On Sat, 10 Oct 2009, Jesús Gabriel y Galán wrote:

or about
class_eval, etc) so I answered the one that was “has it’s place” or
something like that.

If we are talking exclusively about pure eval, I agree with David, I
almost never use it.

I make a distinction between *eval’ing a string, which always carries
all the dangers of regular eval, and the block forms of instance_eval
and class/module_eval, which are very different techniques and don’t
have the same dangers.

David


The Ruby training with D. Black, G. Brown, J.McAnally
Compleat Jan 22-23, 2010, Tampa, FL
Rubyist http://www.thecompleatrubyist.com

David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)

On Oct 10, 2009, at 9:55 AM, David A. Black wrote:

I make a distinction between *eval’ing a string, which always carries
all the dangers of regular eval…

I’m just not sure eval()ing a String or regular ole eval() are alway
dangerous. I wrote about that a little on my blog recently:

http://blog.grayproductions.net/articles/eval_isnt_quite_pure_evil

James Edward G. II

Hi –

On Sun, 11 Oct 2009, James Edward G. II wrote:

On Oct 10, 2009, at 9:55 AM, David A. Black wrote:

I make a distinction between *eval’ing a string, which always carries
all the dangers of regular eval…

I’m just not sure eval()ing a String or regular ole eval() are alway
dangerous. I wrote about that a little on my blog recently:

I don’t think so either; I only mean that all the string eval’ing
techniques are essentially the same as each other, while the block
ones are very different.

David


The Ruby training with D. Black, G. Brown, J.McAnally
Compleat Jan 22-23, 2010, Tampa, FL
Rubyist http://www.thecompleatrubyist.com

David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)

THE RESULTS OF THE POLLS
========================

. Lisp Python Ruby

Eval is evil,
harmful or at
least unnecessary 2 (4.9%) 7 (21.9%) 0 (0.0%)

Eval is useful
but overused 11 (26.8%) 6 (18.8%) 9 (29.0%)

Eval has just the
right place 16 (39.0%) 10 (31.3%) 19 (61.3%)

Eval is useful
but neglected 3 (7.3%) 4 (12.5%) 1 (3.2%)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs