Every time I take a look at Ruby, I am simultaneously intrigued and disgusted. Today I was looking at it once again, pondering the Camping framework for writing web apps, and ran across this explanation of how it works:
Behind the scenes, Camping actually reads its own source file (with the __FILE__ handle) and does a search and replace on all instances of Camping. It then evals the result and runs your app with the modified code!
— from O'Reilly's Ruby column
Argh!! On one hand, I feel like I shouldn't need to care how something is implemented. But I see this sort of thing (building and eval
ing code) so often in Ruby that it makes me worry that the language is incapable of expressing the abstractions that people actually want to build, and it might also be incapable of expressing the things I want to build. I guess I grew up treating eval
as something to use only as a last resort. The only place I felt okay using eval
was Scheme, where it took program trees instead of strings. Ruby still intrigues me though, so I'll probably try a project in Ruby at some point.
Labels: programming
You shouldn't damm something because you have learned to do..
From what I've read so far you seem like a decent programmer with a good head on his shoulders. I think the example you are quoting is going for the "look at the cool stuff you can do with ruby. I agree that some of this stuff probably shouldn't be used or only in very rare cases. Go through Why's Guide to ruby or the like and actually give ruby a try. After 10 minutes I'm sure you basically understand the language and you might even like the clean syntax, the dynamic language, and the solid libraries that come with it. If not, try posting your concerns on the ruby-talk mailing list. There's a great community that won't "flame" you for asking questions and pointing out faults.
Good Luck,
PS check out the shattered library:
http://www.shatteredruby.com/
You're quite right, eval is a pretty scary thing to be using liberally. There are other templating options for ruby though, and there's always Ruby on Rails.
groovy, groovy, groovy
Post a Comment