views:

127

answers:

3

I have seen alot of frameworks that generate stub applications, like Ruby on Rails for example, where most of the code is used for business domain logic, but why do we have generated code still. Wouldn't a library be better?

+3  A: 

A library will consist of common functions or classes that may be used as is in many applications. These frameworks do include libraries of code.

The generated code takes care of the scaffolding that you will need to write yourself regardless. Since most of it is pretty standard, it can be generated and the intention is you modify the pieces that you wish to.

Vincent Ramdhanie
The scaffolding is not what I would call generated code as it has to be written anyway, like in rails.
Zubair
@Zubair I am thinking along the lines of action classes in struts. These can be generated but you fill in the details yourself.
Vincent Ramdhanie
Ok, that makes sense. I think scaffolding is the only acceptable answer then for generated code, do you agree?
Zubair
+1  A: 

With techniques like LINQ I see (almost) no need for the frameworks like NHibernate and similar solutions. When performance is a real issue generated stub applications could be faster than techniques that rely on techniques like reflection.

Another benefit of generated code is that it is compiled and thus less likely to cause errors at runtime.

Zyphrax
Last I checked, NHibernate does not generate a line of code. And Linq To Nhibernate does exist. So your first comment is null.
mxmissile
+4  A: 

There are both justified and unjustified cases of code generation. However proper code generation can result to the following benefits:

  1. Optimal runtime code -- libraries process stuff during runtime, whereas you can eliminate a lot of runtime machinery by analyzing the codes structure during generation.
  2. The elimination of bugs introduced doing repetitive work.
  3. Better understanding of your code, generation generally leads to higher level "model"; where the model is used to represents what needs to be generated.
  4. Reduction in LOC -- thousands of lines can leads to millions of lines of output code.
Hassan Syed
I couldn't agree more. I think the issue arises when someone wants to code gen everything for every scenario. Use it to get you to the 80% mark and do the rest!
Blake Niemyjski