Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we still need generated code?

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?

like image 775
yazz.com Avatar asked Feb 14 '10 14:02

yazz.com


2 Answers

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.
like image 169
Hassan Syed Avatar answered Jan 04 '23 17:01

Hassan Syed


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.

like image 25
Vincent Ramdhanie Avatar answered Jan 04 '23 16:01

Vincent Ramdhanie