views:

497

answers:

11

Do code generation tools do more than create CRUD?

e.g. Say I have a User's table, a code generation tool would then create:

  1. The class
  2. the CRUD: Update/Insert/GetByID/GetAll/Delete
  3. Stored procedures for #2

What other things can/do they generally create?

+3  A: 

Code generation tools are basically rules engines that get input and create text (the code) according to the input given.

I have used CodeSmith to create a class based on the reflection of it from a dll. It all depends on the input and the ability of the tool you're using to run actual code/macro.

Dror Helper
+3  A: 

I used to have a code-gen that would create an entire CMS given a few answers in a form. Every time I started a new project, I would add more to the generator to fit the needs of the new project. For a while, I was knocking out projects in 1/4 the time. But eventually, I found myself spending more time maintaining the generator than I did doing actual client work. It seems best to keep generators quick and simple.

enobrev
A: 

I have seen code generators generate site maps. So therefore you don't mess up typing when your doing a redirect, because it is in your code.

Scott
+2  A: 

Other examples:

If you mean other things that CRUD I have the following examples

Input: language description Output: program that parses this language

Input: processor description Output: compiler for that cpu

Input: web service description Output: communication glue layer to use this web service

Input: list of integers and names Output: source code with error codes in nice enums

tadeusz
A: 

i had used codesmith,the n-tier is a good template,use it you can get well structure application and it generator some just-to-use pages like a scaffold ,besides that the generatored maintain the relationship between different class, recently i'm learn subsonic and i find the synatx is easy to use and i like the activerecord pattern ,base on what kind of application you may some orm tool like nhibernate/ef. sorry for my poor english.

sdhjl2000
A: 

Think about Visual Studio and Typed datasets, Linq to SQL, Entity fRamework, etc, they are all examples of code generators.

mattlant
A: 

Pretty much every program that has a well defined input and produces:
- output for other code generation programs (translating, with or without a configurable template)
- binary code
is a code generation tool. This includes scanner generation tools like flex, compiler generation tools (eg. coco/r) and a lot of other template based code generation tools. Data model/domain model generators are just an example of programs that take the DB schema and generate code in your preffered language to access the data from it.

radu_c
A: 

If you have a generator that uses a templating system like NVelocity, you can generate almost anything you want. For example, we currently generate CRUD, custom enums, SQL functions that map to those enums (for doing queries that return more English-like results) and Windows dropdowns for those eunms. This lets us drop a pre-built control on a Windows form that lets the user select from any value in the enum. We've also had it generate a custom stored procedure that builds a special security role in the database, based on a set of permissions.

Corey McKinnon
+1  A: 

Code generation tools are crucial to programmer productivity and program correctness in many areas. Our "base" languages like C, C++, Java, Fortran, Ada, Python are general-purpose, which means that anything except basic computaiton is bound to end up a messy sequence of function calls, variable creation, etc. Also, the typical imperative languages do not map well to a whole host of domains.

I see telecom people using tools that generate code in a whole variety of places. For example, ASN.1, SDL (the telecom programming language), UML, state charts are all used to generate code from a domain-oriented expresssion to whatever ugly system lies below. Automotive programmers are big on Matlab/Simulink to go directly from a diagram describing a computation to an implementation without manual intervention. Anybody creating a custom language or a compiler are bound to be using code generation tools in the creation of the code generation tool -- lex, yacc, bison, and more advanced tools such as BURS or hte commercial offerings from Target Technology are used extensively.

So yes, most complex systems are coded to a large extent in code-generation tools of various kinds.

jakobengblom2
A: 

One more note: there is a huge difference between a code generator creating code that you then extend and change, and those that just create code that you never care to see. The former category tend to be much harder to do well, as the code has to be more readable and there have to be some kind of handling of what to do when the original design changes.

jakobengblom2
A: 

I'm also working on a CRUD generator w/ the difference that it generates all UI at runtime based on metadata.

http://www.www.evolutility.org