From: avi@...4.com (Avi Bryant) Date: 2002-04-04T05:50:11+09:00 Subject: Re: Is eval a code/design smell? Ron Jeffries wrote in message news:... > On Wed, 03 Apr 2002 00:15:10 GMT, "Chris Morris" wrote: > > >I seem to have an inherent distaste for eval, but I don't know why. I've > >heard it has performance concerns, but that seems to be the only pragmatic > >reason to not use it in cases where that matters. Are there any other > >pragmatic concerns with eval? Is its use a design red-flag? Is there > >something to my gut instinct, or is it a holdover from my strong-typing > >past? > > In my experience and opinion, there are very few valid reasons to use eval. I never use eval. However, I use module_eval all the time. That is, although I never use eval at "runtime", it's extremely useful at, err, "compile" time, to generate code. Look at AspectR or my work a while ago on the Kansas O/R mapping for some examples of this; for an extreme example, look at Matju's X11 implementation. For a less extreme example, consider this - every time you use attr_accessor, you're effectively using eval. Now, in lisp, most of these uses would become macros instead, which I think is ultimately a better solution. But until someone gets around to porting dylan's macro system to Ruby, those of us who can't live without metaprogramming will have to make do with eval.