David Bogus on 6 Sep 2007 04:56:42 -0000 |
Advantages of using language with introspection or reflection to generate code in a language or subset that doesn't have it. First off testing. Testing where you don't have to register your tests or suites is taken for granted until you have to do every time every test. Its about once every other week that you forget to register a test, When working in that environment step one is write a test with explicit fail and watch it fail. That verses extend some class and follow a naming convention, and let the automagic happen. Changing behavior of things for tests. Lets say we are using a simplistic widget library on some small device lets say a dvd player. So just for grins we want to make sure that people can use it in many languages. Here is the kind of test I would like to write. def testSwitchLanguage languages.each do |language| all_menus = menu.new(language).menu.recursive_text all_menus.each do | menu | assert(language.words.contains(menu.text)) end end end Now suppose when we call our simplistic widget library it takes the string but doesn't allow us to get it back. (Imaginary reason it generates a bitmap immediately and frees the string ) So we go and write wrapper that delegates to the simplistic widget library but records the calls and can tell us what text the widget contains. Now I'm sure using introspection in your generated code would be awesome but thats a bit more complicated. Its not all that hard to have your dsl generate some defalut method on your objects like ones that says what method the object understands. Then you can start with just tracking pointers and keeping a "omniscient" object that keeps all objects. Next thing you know you'll start wanting to be able to do dynamic composition. So you take two pointers and check that no messages collide then you generate an code that delegates to on to the appropriate pointer. Of course this is part way along that slippery slope to writing your own language. Question for Greg, what is the type of problem your solving? I'm unclear about "controller models" and what that means to you. Dave -- Dave's Definitions: Morning, is after I've slept for more than four hours. Lunch is the second meal of the day no matter the hour of consumption. A long drive is one longer then you have last slept. Ineffable, if you don't understand I couldn't possibly explain it. _______________________________________________ To unsubscribe or change your settings, visit: http://lists.phillyonrails.org/mailman/listinfo/talk
|
|