News for hackers. Stuff that matters.
Re:It's about time to start fighting against the Rails “magi... by aaronblohowiak on Tuesday December 14, 2010 @04:42AM (#2003678)
Convention over configuration: sane default values.

magic: changing the scope in which a block is eval'd so you can inject BlankSlates that have method_missing defined on them that then do some string manipulation in order to pick which code path to take.

Sometimes you need to lean pretty hard on the super-dynamic features to get the api you want. But is it worth it?

Re:It's about time to start fighting against the Rails “magi... by JonnieCache on Tuesday December 14, 2010 @07:01AM (#2003893)
is this the routing DSL you're referring to here? The activerecord query building stuff is much simpler than this, i know that.

If anyone wants to get a head start in understanding the magic, Ryan Bates has done excellent walkthroughs of the routing DSL and the activerecord query building method chaining source code:

http://railscasts.com/episodes?utf8=%E2%9C%93&search=wal...

edit: to add to the list of stuff that rails does which is 'magical,' I still get uncomfortable over the way that instance variables I set in the controller scope are 'copied' to the view scope. This is obviously a necessary evil though.

The real cost of rails' magic is the rampant and wanton Demeter Violation, which can make testing very difficult in some circumstances.

http://en.wikipedia.org/wiki/Law_of_Demeter

Re:It's about time to start fighting against the Rails “magi... by alextgordon on Tuesday December 14, 2010 @09:10AM (#2004153)
"Ugh, I made this routing library, but the API is such a hack."

"What about calling it a 'DSL' rather than an API? Then nobody will be able to claim you're abusing Ruby, because it's an entirely new language!"

"I doubt anyone would ever buy that..."

Re:It's about time to start fighting against the Rails “magi... by JonnieCache on Tuesday December 14, 2010 @10:09AM (#2004383)
Its called a DSL because it is extremely declarative, and because while it is obviously a subset of ruby syntax, it does not have to look like common ruby at all.

I take your point though, I do get that feeling sometimes. There is a lot of showing off by ruby API developers.

I think there comes a time in every ruby hackers life when they get the urge to write an API that makes use of every single metaprogramming/reflection/self-modification feature in the language, because it looks like so much fun. We spend our work days writing rails with all its fancypants DSL-like bits, and we think "I want to do one of them!"

Mine is a DSL for defining regular expressions in natural language, and my god does it abuse metaprogramming. All the methods are defined at runtime by iterating over datastructures that list the regex spec. instance_eval(&block) all over the place. It is fucking brilliant. And not finished. Obviously.

Re:It's about time to start fighting against the Rails “magi... by ollysb on Tuesday December 14, 2010 @10:18AM (#2004413)
The point about the templates is that they're evaluated in the same context as the actions. Have a common context between the controller and the view makes a lot of sense to me. I don't see any reason why this is necessary though, you could always pass a context object to the template parser.
Re:It's about time to start fighting against the Rails “magi... by collint on Tuesday December 14, 2010 @11:13AM (#2004593)
The point of rails is that when there is something "you could always do" you find a way never to do it.
Re:It's about time to start fighting against the Rails “magi... by ollysb on Tuesday December 14, 2010 @12:52PM (#2004989)
I'm going to bite and just say YAGNI