Beta

Slashdot: News for Nerds

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Code Generation in Action

timothy posted more than 10 years ago | from the automation dept.

Java 262

Simon P. Chappell writes "Now, I enjoy a good technical book more than the next geek, but it's been quite a while since one left me quite so excited with the possibilities that it presented. Code Generation in Action is beyond interesting, it is a masterful tome on its subject matter, written by one who is obviously an experienced practicioner in his craft." If "code generation" isn't a familiar term to you, this enthusiastic overview on devx.com is a concise introduction to what code generation is about, though it makes no pretense of ambivalence about its importance as a programming tool. Read on for the rest of Chappell's review.

Overview

Code Generation in Action, CGiA to its friends, is presented in two parts. The first part is four chapters, and covers a code generation case-study, the basic principles of code generation, including the different types of code generation strategies together with reasons why you would or would not use each strategy. The book's chosen toolset for building generators is presented next, and then some walk-through examples of building simple generators wraps up the first part.

The second part is a kind of a cross between a cookbook and a list of engineering solutions. There are nine chapters with the breadth of solutions covered being quite impressive, covering the gamut of generation of user interfaces, documentation, unit tests and data access code. Each chapter presents a couple of solutions within its topic area, often for different technologies within that topic. For example, the user interface chapter covers the generation of Java ServerPages, Swing dialog boxes and then Microsoft MFC dialog boxes. No favouritism here!

What's To Like

There's a lot to like with this book. The writing is very clear and of good prose. I found the introduction to be very compelling, and I felt completely drawn in by the opening case-study. The four chapters of part one are a concise case for code generation, and would be very useful information to help persuade co-workers and management of the positive risk/benefit ratio with trying code-generation on a live project.

It would be impossible to try enough of any solution from part two in a time-frame short enough to make this review useful, but in the solutions that match my areas of knowledge, I found myself admiring Herrington's straight-forward and pragmatic approach.

What's To Consider

There are two aspects of this book that I want to flag. One of these aspects, some will love and others will hate, and that is the choice of generator language for CGiA. The author has chosen to use Ruby as his working language. This is an interesting choice. Ruby is certainly a language that is inspiring a lot of admiration these days (in fact, it's hard to get Dave Thomas to stop talking about it :-), but with the majority of the code-generation examples being for Java-related technologies, I wonder why Java was not selected instead.

I also found myself wondering about the lack of discussion of how to integrate these Ruby tools into a typical Java build process. Many developers I know use ant to bring automation and consistency to their builds, yet the book doesn't mention this. (JRuby anyone?) Certainly something to consider for the second edition or future code-generation authors.

Summary

This is a masterful tome that inspires and delights, although the two issues raised above did cost it a perfect score of ten.

Table Of Contents

  1. Code generation fundamentals
    1. Overview
    2. Code generation basics
    3. Code generation tools
    4. Building simple generators
  2. Code generation solutions
    1. Generating user interfaces
    2. Generating documentation
    3. Generating unit tests
    4. Embedding SQL with generators
    5. Handling data
    6. Creating database access generators
    7. Generating web services layers
    8. Generating business logic
    9. More generator ideas


You can purchase Code Generation in Action from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

cancel ×

262 comments

Moo... (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#6870082)

Moo?

vaca? (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#6870149)

I belong to the Code Generation... (4, Funny)

burgburgburg (574866) | more than 10 years ago | (#6870088)

And I can take it or leave it if I please.

Richard Hell and Codeoids

Re:I belong to the Code Generation... (1)

gowen (141411) | more than 10 years ago | (#6870522)

Not really Richard Hell, since "blank" -- the word you've changed -- was his only contribution to that lyric. The rest goes back to Rod McKuen (or "the woeful Rod McKuen" to give him his full title), who wrote "I Belong To The Beat Generation"

Was it really necessary? (-1)

Sir Haxalot (693401) | more than 10 years ago | (#6870092)

Table Of Contents 1. Code generation fundamentals 1. Overview 2. Code generation basics 3. Code generation tools 4. Building simple generators 2. Code generation solutions 1. Generating user interfaces 2. Generating documentation 3. Generating unit tests 4. Embedding SQL with generators 5. Handling data 6. Creating database access generators 7. Generating web services layers 8. Generating business logic 9. More generator ideas
Was it really necessary to put a table of contents?

Re:Was it really necessary? (1)

jared_hanson (514797) | more than 10 years ago | (#6870168)

to ask this question?

It's a book review for crying out loud. People like to know the specifics of what is covered, and the table of contents helps out. I find it encouraging that the chapters stick to the topic in the title. I'd probably not buy the book if there was a chapter entitled: 10. The F6 key, right between F5 and F7.

good stuff (4, Interesting)

DreadSpoon (653424) | more than 10 years ago | (#6870118)

Code generation is definitely something programmers of large/complex projects should look into. There's a lot of different forms of it, and I'd be surprised if people haven't used on form or another already.

My personal favorite trick at the moment is describing interfaces in XML, and getting multi-language bindings and docs out of it with a few XSLT scripts. Techniques like that makes script language bindings easy as pie (as do other systems like Swig).

Re:good stuff (5, Funny)

SpamJunkie (557825) | more than 10 years ago | (#6870173)

Code generation is definitely something programmers of large/complex projects should look into. There's a lot of different forms of it, and I'd be surprised if people haven't used one form or another already.

Ya, I've done some code generation myself. I used a text editor and my brain. How does everyone else do it?

I thought about using my wang instead of my brain but he just types screenfulls of the V word.

Re:good stuff (1)

ShadeARG (306487) | more than 10 years ago | (#6870328)


I'd be surprised if people haven't used on form or another already.
Using an autogen.sh generated configure script to prepare a source tree for compilation qualifies as this at some level if I'm not mistaken.

Re:good stuff (1)

a_ghostwheel (699776) | more than 10 years ago | (#6870395)

I use it all the time on large projects. Mostly using either Java or Perl to implement generators (it depends on the source that is feeded to generator). Plus on large projects part of code generation is usually embedded into the desing/modeling tools that are used there (Rational Rose being obvious example). XML/XSLT approach is a way to go now though - I would agree with this.

Re:good stuff (2, Insightful)

zero_offset (200586) | more than 10 years ago | (#6870734)

Ugh. XSLT is a nightmare.

We farmed out a project to a company which used a ton of "elite" off-shore resources, and they sent back a project which relied heavily on XSLT. Granted it made sense on paper -- prior to their involvement, the data was already available in XML format. But the net result was a nightmare to debug, maintain, and upgrade. XSLT reminds me of the old saying about APL -- it's a "write-only" language.

Ok, I concede it's not actually as bad as APL, but it isn't nearly as easy to debug as regular old XML DOM based code, and we've done some side-by-side tests that adequately prove (to us; hey, they're our tests) that the code isn't any more concise or easy to write. We already knew it was harder to read and debug. And the current crop of parsers seem to run XSLT a LOT slower than the equivalent DOM calls. It strikes me as a solution in search of a problem...

You completely inhale the pastes in crust (-1, Troll)

Anonymous Coward | more than 10 years ago | (#6870122)

It has come to my attention that you completely inhale the pastes in crust. Read on for more about this fascinating topic.

The world went into shock a few weeks ago when goatse.info [goatse.info] reported the results of a study which concluded that inhaling paste is a very dangerous pastime, one that no one is advised to take up. Eventually, everyone adapted to the new state of affairs and began inhaling other things. Almost everyone, that is. But not you! According to my records, you still inhale paste!

Why?! What the fuck is wrong with you?!

You moron, you idiot, you imbecile, you gay nigger [nero-online.org] ! Arg! You make me so fucking sick! FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU.

goatse.info... (0)

Anonymous Coward | more than 10 years ago | (#6870491)

That is a fucking good site. I think I'll switch from /. to there!!

Software Engineering is not just there yet (1, Interesting)

stonebeat.org (562495) | more than 10 years ago | (#6870136)

Software Engineering is not just there yet. It is a nice concept, but not pratical. Rational Rose does it to a certain extent.

Re:Software Engineering is not just there yet (0)

Anonymous Coward | more than 10 years ago | (#6870204)

Agreed. Generated code still has to be reviewed and debugged. Plus it is generally bloated. I have seen code generators generate 100K + lines for simple tasks.

Re:Software Engineering is not just there yet (2, Insightful)

a_ghostwheel (699776) | more than 10 years ago | (#6870337)

Nobody is talking about completely automating whole development. But there are two things where code generation helps immensely: 1) "mundane code", like accessor/mutator methods , class/interface definitions, standartized header comments, object mapping - this is covered by generators built into the Rose and similar products. Very helpful. 2) Ability to specify business rules in more efficient form (be it XML, some proprietary language, etc) and generate code appropriate for your framework. This is technique which I personally used several times on large custom software development projects - code quality goes way up. To the certain extent same approach is used in any modern RAD tool.

Re:Software Engineering is not just there yet (4, Informative)

johnnyb (4816) | more than 10 years ago | (#6870464)

Actually, it's very much there. It's not a _replacement_ for development, but there are many parts of coding which is benefitted by code generation. I often write tools to write code for me. Once I had to write a color-picker in HTML (VERY repetitive code), so I wrote a code-generator in Emacs Lisp and it saved me several hours. Several implementations of this concept exist:

* Templating (see Alexandrescu's book on Modern C++ design)

* Macros for those in the Scheme/Lisp world (these are GREAT and AWESOME)

* Compile-time programming (only available in LISP as far as I'm aware through the eval-when construct)

* Custom program-generators

And then there's the related concept of partial evaluation that, while excellent, has received very little attention by the commercial sector.

Now, many code-generation facilities could be done better with good libraries, but this isn't universally the case. Delphi is probably the best at putting in libraries/properties what others put in code generators, and their software is much easier and better because of it.

Macros and compile-time programming are two of the best ways to do this, but Scheme and LISP are the only ones that do this reasonably.

THIS BOOK SUCKS.. (-1, Offtopic)

Anonymous Coward | more than 10 years ago | (#6870142)

monkey dong or a eurofag

Something missing? Like a definition? (5, Insightful)

Trigun (685027) | more than 10 years ago | (#6870147)

Code generation is a time-saving technique that helps engineers do better, more creative, and useful work by reducing redundant hand-coding. In this world of increasingly code-intensive frameworks, the value of replacing laborious hand-coding with code generation is acute and, thus, its popularity is increasing.

Why not put a little bit about code generation in the review. Even a little blurb like "It builds the mundane portions of coding" would have helped out a bit.

Re:Something missing? Like a definition? (1)

robbyjo (315601) | more than 10 years ago | (#6870365)

Eh? This is different than I would expect. In the "formal" computer science definition would be something like generating code (often times machine code or byte code) in compiler context.

Also, in computer software design, it has another definition. Namely: Generating real code (C, C++, Java, whatever) from design templates (like from UML).

Now, these people are overloading the same term?? These make me even more confused.

Re:Something missing? Like a definition? (1)

Trigun (685027) | more than 10 years ago | (#6870447)

Now, these people are overloading the same term?? These make me even more confused.

Which is why I generally don't bother reading more than the back cover of these types of books, and stick to the O'Reilley series, or an equivalent. It seems more and more that the book reviews are just so some slashbot can make a few quid on the referral incentives.

O'Reilley has never steered me wrong. Slashdot and Amazon however...

Re:Something missing? Like a definition? (1)

arekusu (159916) | more than 10 years ago | (#6870448)

In this world of increasingly code-intensive frameworks ...I guess NSController doesn't count for anything?

Bah (-1, Offtopic)

stratjakt (596332) | more than 10 years ago | (#6870158)

What you really want is CO-EDs IN ACTION.

Does copy and pasting SCO's NUMA code count as code generation? Someone ask Linus.

GNAA! (-1, Troll)

Anonymous Coward | more than 10 years ago | (#6870175)

The Gay Nigger Association of America (GNAA) is the group that represents the world's Gay Nigger population as well as those non gay, non nigger patrons that support it. Its mission is to foster a gay and free-loving climate that supports and promotes our members' creative and financial vitality. Its members are the gay niggers that comprise the most vibrant national gay nigger conglomerate in the world. GNAA members create, manufacture and/or distribute approximately 90% of all legitimate pro-homosexual propaganda and blue, rubber dicks produced and sold in the United States.

We strongly urge you to join the GNAA and support our cause. Gay Niggers everywhere need your help!

BE NIGGER!

BE GAY!

JOIN THE GNAA!!

Join #GNAA on the EFNet IRC Network today! (irc.secsup.org, irc.easynews.com, irc.servercentral.net)

________________________________________________
| ______________________________________._a,____ |
| _______a_._______a_______aj#0s_____aWY!400.___ |
| __ad#7!!*P____a.d#0a____#!-_#0i___.#!__W#0#___ |
| _j#'_.00#,___4#dP_"#,__j#,__0#Wi___*00P!_"#L,_ |
| _"#ga#9!01___"#01__40,_"4Lj#!_4#g_________"01_ |
| ________"#,___*@`__-N#____`___-!^_____________ |
| _________#1__________?________________________ |
| _________j1___________________________________ |
| ____a,___jk_ GAY_NIGGER_ASSOCIATION_OF_AMERICA_|
| ____!4yaa#l___________________________________ |
| ______-"!^____________________________________ |
` _______________________________________________'
-posted by GNAA member Penisbird

Get it from just $25.29! (1)

anonymous coword (615639) | more than 10 years ago | (#6870180)

Re:Get it from just $25.29! (0)

Anonymous Coward | more than 10 years ago | (#6870279)

again, change yr URL to point to a directory named 'natalie' instead of 'goat' and more ppl will fall for clicking on yr sig URL. your prompt attention to this matter is greatly appreciated. keep on trollin'.

P

www.nataliegoat.com (0)

Anonymous Coward | more than 10 years ago | (#6870587)

I'd buy that for $1!

How big a pool of contributors do you think we need to pay NP to give set us up the goat?

Indian Consultants and Code Generation (2, Funny)

Anonymous Coward | more than 10 years ago | (#6870189)

This book looks like a poor excuse for management drivel! If we could just get rid of those pesky programmers ... ah! Code Generation! Couple this with the move to push everything offshore ... and voila! no more pesky programmers. Now if we could just get them to finish the powerpoint compiler the development team was working on .... PHB

Re:Indian Consultants and Code Generation (1)

a_ghostwheel (699776) | more than 10 years ago | (#6870445)

Spoken like a true architect. :) Imagine - just you and a bunch of code generators... and nothing to worry about :D

Damn, it sounds almost like I am ready to welcome code generating overlords.

Wow. H1-B in a can!!! (1, Funny)

Anonymous Coward | more than 10 years ago | (#6870220)

coding's not hard. just create these dots and we'll connect them for you. just press a button.

Code generation == metaprogramming (5, Insightful)

Anonymous Coward | more than 10 years ago | (#6870221)

And Lisp has been doing it for years, as has, to a lesser extent, C++ (and Ada) templates. And the good thing about Lisp metaprogramming is that it is in the one language - lisp.

Having 1 language generating another - Ruby and Java - is the recipe for confusion and complexity.

Yea. Ok. Perl do it, too. (0)

Tei (520358) | more than 10 years ago | (#6870290)

And also Perl provide some features that where very cool to generate Perl. Sooo cool that you can have a Perl app that generate his own source. You can do that with Lisp?

Re:Yea. Ok. Perl do it, too. (0)

MrBlint (607257) | more than 10 years ago | (#6870401)

You can do it BASIC very easily
10 LIST

Re:Yea. Ok. Perl do it, too. (0)

Anonymous Coward | more than 10 years ago | (#6870451)

Perl, cpp, m4, C++, and other code-generation systems do TEXT substitution/rewriting. Lisp macros do CODE substitution/rewriting. There's a big difference. "Those that do not understand Lisp are doomed to reinvent it. Poorly."

Re:Yea. Ok. Perl do it, too. (-1)

Genghis Troll (158585) | more than 10 years ago | (#6870613)

You can do that with just about any language. Such programs are called quines [nyx.net] .

Re:Code generation == metaprogramming (0)

MrBlint (607257) | more than 10 years ago | (#6870351)

Like a java program that generates javascript code for a web page; that can get really confusing.

Re:Code generation == metaprogramming (1)

i3spanky (191866) | more than 10 years ago | (#6870458)

Great, Lisp is cool, but generating more Lisp in Lisp is a very limited case.

I'd wager that most often you really don't want to be writing a code generator in the same language that you're generating.

Take my last code generator: imagine writing Sybase triggers using Sybase's stored procedure programming language. Trust me, python (or perl/awk/ruby/C) was much better suited to this task.

Further, as you write more code generators you'll start to develop your own suite of tools, and if written properly these will be highly reusable regardless of the target language.

Re:Code generation == metaprogramming (0)

Anonymous Coward | more than 10 years ago | (#6870485)

Your wager means that at least one of your languages sucks -- either a bad source, or a bad target, or a bad tool.

Re:Code generation == metaprogramming (1)

a_ghostwheel (699776) | more than 10 years ago | (#6870505)

Having generated code means that you now rely on code generator being properly implemented (usually by few "cream of the crop" developers on your project) vs relying on several dozens of junior developers to code same stuff while they cannot even understand trivial concepts. Usually your experienced developers will end up spending same amount of time consulting rest of the development team that they will spend writing code generators for most of the code (hyperbole but not that far from the truth).

At least this was true on all large (50+ developers) projects I worked on.

embeded generated code into handwrite code. (0)

Tei (520358) | more than 10 years ago | (#6870225)

Other option:

You can use external tools (perl scripts,etc..) to generate some really boring files that withouth this tools need to be by hand.
Code write by hand can have really hard to fix bugs, its better to do it automatically.
And if everything is sync with "make", you have a beaty machine.

Wild (2, Funny)

mao che minh (611166) | more than 10 years ago | (#6870233)

"Code Generation in Action"

They make the visual of some pale, skinny nerd with a "Got Root?" shirt on, banging away on a keyboard in a poorly lit dorm room sound exciting.

Re:Wild (2, Funny)

Gr33nNight (679837) | more than 10 years ago | (#6870332)

Hey bastard, just for your information I put on 20 lbs in the past 4 months!

Congratulations (1)

Trigun (685027) | more than 10 years ago | (#6870469)

Is there a party when you break 100?

Re:Congratulations (2, Funny)

Gr33nNight (679837) | more than 10 years ago | (#6870607)

The sad thing is, I read that 100 as binary ;/

Re:Congratulations (0)

Anonymous Coward | more than 10 years ago | (#6870633)

I hear that the fire dept comes over when you hit 700# and lifts you to the hospital on a crane!

Re:Wild (1)

Grant_Watson (312705) | more than 10 years ago | (#6870612)

They make the visual of some pale, skinny nerd with a "Got Root?" shirt on, banging away on a keyboard in a poorly lit dorm room sound exciting.

My room is well lit, you insensitive clod!

We didn't know we were doing anything special... (4, Insightful)

Fnkmaster (89084) | more than 10 years ago | (#6870240)

But we built a very large code generation system as part of my old company's electronic trading system. It used the JavaDoc system and a custom JavaDoc parser we built to generate oodles and oodles of very repetitive code from the base business objects, such as XML parsers and translaters and the like. It was a big time saver, undoubtedly. The big problems we had were versioning and its interaction with our build system, and more importantly, the fact that the code generator itself becomes very complex to read, such that only one or two developers are capable of making changes to it.


My rule of thumb is if I find myself writing code that bores me silly and thinking "a frigging monkey could be taught to code this piece", I will strongly consider writing a program to write the program for me. Be warned about the maintenance and readability issues though in larger development projects where there are a lot of mediocre programmers around. You can always assign those mediocre programmers to hack on monkey-easy code, but you can't get them to hack on a code generator, so carefully consider the nature of the development organization you are dealing with, and the tradeoff between available "high-value" time and resources vs. "low-value" (i.e. monkey coder) time and resources. This perspective has been brought to you by my pointy-haired side.

Re:We didn't know we were doing anything special.. (2, Informative)

sircrown (82531) | more than 10 years ago | (#6870409)

You might want to check out XDoclet [sourceforge.net] next time rather than write your own parser/generator. It's pretty widely used now and has lots of tags for many common uses like EJBs, Hibernate, web.xml generation for all the major appservers, etc. It's also integrated with Ant and it looks like Sun is going to be borrowing some ideas for use in Java 1.5+.

Re:We didn't know we were doing anything special.. (2, Interesting)

Fnkmaster (89084) | more than 10 years ago | (#6870605)

Well, we used XDoclet as well. Actually, it was EJBDoclet originally, back when we started using it - this was several years back, mind you. EJBDoclet became a subset of our build system. But our custom JavaDoc modules wouldn't really have benefitted much from anybody's framework, honestly, and we had by then 90% decoupled our system from the EJB way of doing things. For example, we auto-generated EJB session beans that used direct DB access for bulk updates and retrieval, because entity beans were insanely slow. In fact, we were also autogenerating the input files for EJBDoclet at the time, since they were sort of EJB "shell classes", and EJBDoclet generated the rest of the annoying EJB stuff.


Like I said, I have no idea what people are doing these days, this was back during EJB 1.1 days, pre-2.0, and we had a primarily message-based system that used JMS or other non-JMS compliant messaging systems like TIB. Thank god I don't have to touch EJB/Enterprise Java with a 10 foot pole anymore, since it's one of the most poorly designed systems imagineable - I love a lot about the Java language, but Enterprise Java needs to die a slow death.

Re:We didn't know we were doing anything special.. (1)

smagoun (546733) | more than 10 years ago | (#6870546)

There's an open-source implementation of a very similar generation system living at http://sandboss.org [sandboss.org] . It does everything from bean classes to database schemas, and unlike many code generators it's not tied (implicitly or explicitly) to any particular output like EJBs or XML. Although written in Java, the underlying generator architecture is designed to spit out C code just as happily as it spits out Java. The Sandboss generator infrastructure is part of a larger framework for building message-based enterprise apps, and it makes adding new interfaces to those apps much easier.

Unlike other generation engines, the Sandboss engine concentrates on the application requirements + not the implementation technologies (EJB/XML/etc). Using Sandboss, you can plug in new generators (to change the persistence layer from EJB to straight JDBC) without modifying your app's code *at all*. Generators like XDoclet embed technology dependencies right into your app's code, which makes switching technologies harder. I'm a developer on the project so perhaps I'm biased, but I think it's pretty damn cool.

The parent is right to warn about maintenance. Meta-progamming of any kind requires a little more thought + understanding than many coders are used to. Generators are basically power tools, and as with any power tool if you're not paying attention you're likely to get yourself into trouble.

Code generation and Pragmatic programmer (4, Informative)

gbvb (304328) | more than 10 years ago | (#6870241)

if you ever read the "Pragmatic Programmer" book about software developer practices, it mentions that they used code generation for many things. Code generation definitely helps when you have many similar but not same implementation.. But, in Java or any other object oriented languages, inheritence can be used to avoid similar looking code (which is what code generation would do).
But, even here, I think the UI pages, or template based generators definitely help. There was a tool by DevelopMentor which used to generate code for ATL. It was based on templates..

this post mentions monkeys (0, Offtopic)

turkeyphant (648612) | more than 10 years ago | (#6870243)

Why doesn't it cover the infinite number of monkeys on typewriters method that Microsoft is clearly still debugging?

NOT about compiler code generators (5, Interesting)

GillBates0 (664202) | more than 10 years ago | (#6870244)

I've been doing R&D work with compilers (Ada/C(++)/Java(bytecode generators)) for quite a while now, and the first thought that occurred to me was that this is an article/book about the code generator pass in compilers.

But apparently, it is not. I, for one, wasn't too happy seeing the term "code generator" applied to superficial software that generates HTML/user level code for standard dialog boxes etc. HTML isn't code in the first place, anyway.

Maybe I'm being too fussy about this, but a code generator, traditionally has always meant a part of the compiler back-end which actually translates intermediate code to machine-level instructions. VB and other UI tools generate stubs for the most part...well maybe they are code generators, but I'm just not too happy about the choice of terms.

Re:NOT about compiler code generators (0)

Trigun (685027) | more than 10 years ago | (#6870288)

For the most part KDE/QT is the same thing. Draw a fancy user interface, let it generate the code to show it, then fill in the blanks.

If they made a program that filled in the blanks, then I'd say "oooh", but this seems pretty old hat now.

Re:NOT about compiler code generators (1)

tomhudson (43916) | more than 10 years ago | (#6870318)

Except that you could apply the same techniques to create c/c++ source files, header files, etc. The whole concept is to create a "tiny compiler language", that does the job you want it to do. Heck, you could even generate assembler if you wanted.

It's about bringing the power of #include and #define to other environments, as well.

Remember, programs that write programs are the happiest programs in the world.

Re:NOT about compiler code generators (3, Insightful)

naarok (102579) | more than 10 years ago | (#6870700)

A code generator is a compiler. It takes some source and produces an implementation of the source using a more primitive language.

I wrote a code generator for EJBs. The template that was passed in was very much the source as a very high level language. The output was Java code.

I wrote a Pascal compiler for a virutal machine. The source taken in was Pascal, the output was VM code.

The two were very similar except the gramar for the code generator was much simpler so I didn't need a complex lexical parser.

Don't dismiss code generation as some trick. It is a very valid approach to simplifying repetitive steps and is as much a compiler as what you are thinking of.

in Action? (1)

messju (32126) | more than 10 years ago | (#6870262)

if i want to see code generation in action i do
cd /usr/src/linux && strace -F make

ah hell (0)

Anonymous Coward | more than 10 years ago | (#6870266)

just VS .NET. it does all the work for you. or so the ads say.

Can't be read (1, Funny)

Anonymous Coward | more than 10 years ago | (#6870269)

Too many buzzwords!

Why ruby to generate java code. (1)

JumpSuit Boy (29166) | more than 10 years ago | (#6870282)

I wrote a generator that took a sql file and generated a light java database persistance layer. My reasons for doing this, in Ruby and not Java ,boiled down to the horror of manipulating Strings in java vs. the ease of it in Ruby.

The other advantage using one language to generate another is that there is less confusion about what code is part of what. In my case I had ruby in the generator and java and MS sql in the text blocks that were being generated so it was easy tell thing apart.

Am I FUD? (2, Insightful)

mcc (14761) | more than 10 years ago | (#6870283)

Code Generation is for people who don't understand or are too lazy for abstraction, and it will ALWAYS have the problem of, what if you want to go through all your projects and change one single thing about the generated part of your code? What if you have a hundred tiny projects, each of which contains the generated code snippet that needs to be changed? Let's hope either the change you want to make is very simple or you are very good at regular expressions.

If you are able to clearly separate your code into "You can edit here" and "You cannot edit here" chunks, you can DEFINITELY seperate your code clearly into local chunks and delegated chunks-- i.e., "you cannot edit here" means you just do stuff, "you can edit here" means you talk to a delegate object or method. If EJBs are so frigging complicated that you have to do a bunch of repetitive grunt work that's the same every time you do it, you should somehow be building a slightly higher-level abstraction off of the things you do in common on each EJB and working from there. If EJB does not make this possible you should perhaps not be using EJB. There's always some way to do these things through abstraction, and it will ALWAYS in the end wind up more flexible then either generated or cut and paste programming.

If you've got a code generator sitting around, then sure, go ahead and use it. But I cannot think of any case in an object-oriented language where it would be both less work and more maintainable to write a code generator than to just abstract away the parts that would be autogenerated..

Re:Am I FUD? (1)

revscat (35618) | more than 10 years ago | (#6870428)

Code Generation is for people who don't understand or are too lazy for abstraction, and it will ALWAYS have the problem of, what if you want to go through all your projects and change one single thing about the generated part of your code?

While I completely agree with your statement, I don't think it wholly applies to cases where you are using code generators to do things like generate an XML config file, or other such cases where you are using different technologies that don't talk to each other well. XDoclet is an example of this: among other things you can use it to generate your servlet container configuration files based totally upon comments in your source code, or your custom tag configuration files, including TLDs.

Having said that, I completely agree that using a tool to generate actual source code seems to be lazy design. Some form of abstraction/factory/builder/whatever should be able to take care of just about all of these cases.

Plus, it just strikes me as being so inelegant.

Re:Am I FUD? (3, Insightful)

querencia (625880) | more than 10 years ago | (#6870501)

Code Generation is for people who don't understand or are too lazy for abstraction

The article that timothy suggested as background reading (here [devx.com] ) points out that code generation is most useful when you're forced to use a framework that requires lots of simple-minded "scaffolding-style" code. EJB is the prime example.

In other words, I agree with you --- if code generation is useful, it's probably because the infrastructure you're using was poorly designed. But that doesn't mean you don't have to use it. Managers who have no idea what J2EE is require you to use J2EE. So you use code generation.

Re:Am I FUD? (2, Interesting)

eggsurplus (631231) | more than 10 years ago | (#6870514)

One area where code generation is very handy is in creating java code to interface with a specific database. Based on the type of interface I want (select, insert, update, delete) and the database I can easily create the classes in minutes saving me days of valuable time. In my case I use this to convert data between 2 databases which could be any number of totally different databases. Now only the conversion procedure needs to be coded (for now).

Re:Am I FUD? (1)

neutron2000 (409922) | more than 10 years ago | (#6870650)

Yep ya' are :)

If you are able to clearly separate your code into "You can edit here" and "You cannot edit here" chunks, you can DEFINITELY seperate your code clearly into local chunks and delegated chunks

Sure--but I don't want to manually code my local chunks, either.

I have a completely swell OO system that abstracts functionality and data like it's supposed to but the subclasses are still similar and tedious.

Dave

Wow...what an empty topic! (0, Flamebait)

Junks Jerzey (54586) | more than 10 years ago | (#6870287)

When I saw the term "code generation," I immediately expected it to be about compilers. That's how the term has been used for, hmmm, 40+ years now. And it kinda is about compilers, sorta, in a bizarre, "charts & diagrams" software engineering kind of way. But you have to hunt to find a solid definition of the modern buzzword "code generation" that doesn't reference other unexplained acronyms and terms. And the review doesn't explain it either!

This is one of those depressing, faux engineering, topics like "patterns" and "factoring." Once you dig behind all the buzz and feelgood articles, you find out that it's simply a popular renaming of what's been standard practice since before most of us were born. ("Factoring" was a key topic in most Forth books from the early 1980s, but it has been reinvented and rebranded as a cool 21st century thing.)

Code Generation in Java... (1)

nettdata (88196) | more than 10 years ago | (#6870330)

I use XDoclets a LOT. I mean A LOT. It does some really cool stuff for us, from dealing with MBean interfaces to just about anything else that you can think of.

It's also very tightly integrated with ant [apache.org] and maven [apache.org] , the two build tools that are used in just about every project I'm involved in.

You can find out more about it here [sourceforge.net] .

I guess that is what I did (1)

mathematician (14765) | more than 10 years ago | (#6870339)

I did some code generating in my program xkbset, which is a CLI program to set various parameters of the XKB features of X Window. The program is a bit like xset, and so one might write a line like:

xkbset bouncekeys 4 -mousekeys sticky -twokey

to set various parameters. Well basically the program is a loop that goes through argv interpreting the arguments using a bunch of if statements (just like the internal structure of xset). It seemed like way to much work to write all these if statements, so I wrote a "configuration" file that defines the various arguments, and a perl script that turned the configuration file into a C program.

It was a home grown code generation attempt. I really am quite pleased with it, and it is the only open source program I have written that people actually seem to use (mostly people with Toshiba laptops that need to get rid of key bouncing problems).

http://www.math.missouri.edu/~stephen/software/# xk bset

(Somehow there is an extra space added in the URL between the k and the b - it shouldn't be there.)

My Code Generation Experience (1)

mofochickamo (658514) | more than 10 years ago | (#6870350)

I have written several code generators at my place of work. One of them generates SQLServer, Oracle, and PostgreSQL specific code from a generic SQL file. Another generator creates C code for an install program from an install specification (much like InstallShield). Yet another generator create C code for a resource library from a resource specification.

All of these generators had two things in common: they used Bison as the parser and Flex as the lexer. Since the book uses Ruby in its examples I doubt that it covers Bison and Flex, which is a shame since they are extremely useful tools.

Another thought I had is this: where is the line drawn between code generation and compiling? Are they the same thing? The Dragon Book (Compiler - Principles, Techniques, and Tools), says "...a compiler is a program that reads a program written in one language - the source language - and translates it into an equivalent program in another language - the target language." They seem like the same thing to me.

Re:My Code Generation Experience (1)

stratjakt (596332) | more than 10 years ago | (#6870651)

Code generation doesnt mean compiling. If you wrote a program to translate Java to C or some such, one could call that a compiler. But if you write a program to say, scour a C file and generate the needed #include directives, it's a code generator but has nothing to do with compiling.

This is a form of code generation I use all the time when I restore a database to test against and screw up all the permissions, which I always seem to do in SQL Server:

CREATE ROLE DBAdmin
GO

SELECT 'GRANT REFERENCES, UPDATE, SELECT, INSERT, DELETE ON ' + name + ' TO DBAdmin' FROM sysobjects WHERE xtype = 'U'
GO

I run that and get a nice result set with all the GRANT statements I need. A similar statement gives me execute permissions on stored procedures. Beats typing 75 statements in a row. It's trivial, but its technically code generation.

Ruby not Java (4, Informative)

Colonel Panic (15235) | more than 10 years ago | (#6870363)

The author has chosen to use Ruby as his working language. This is an interesting choice. Ruby is certainly a language that is inspiring a lot of admiration these days..., but with the majority of the code-generation examples being for Java-related technologies, I wonder why Java was not selected instead.

I think the author makes it pretty clear why he chose Ruby instead of Java. Essentially, in order to parse text (which is one of the primary functions in code generators) you would have to write 2 to 3X more code in Java than you would in Ruby. Java is not an optimal text parsing language - first off you have to find a regex engine for it. That leaves you with choosing one of the scripting languages: Ruby, Perl or Python.

Here's what the author says about the cons of using Java for code generation (page 41):

* Java is not ideal for text parsing. (I would agree)
* Strong typing is not ideal for text processing application (again, I would tend to agree, strong typing only gets in your way)
* The implementation overhead is large for small generators. (you'll be writing a lot more java code than you would in Ruby to get the same thing done)

Overall, I'm finding it to be a great book, and the use of Ruby for implementing the examples is a plus as far as I'm concerned.

As far as integrating Ruby into the build process goes, I recall hearing something about a project that uses Ruby to drive Ant.

Re:Ruby not Java (1)

DevilM (191311) | more than 10 years ago | (#6870446)

Find a regex engine for Java? You mean like the one that is included in JDK 1.4?

Re:Ruby not Java (1)

egomaniac (105476) | more than 10 years ago | (#6870593)

Java is not an optimal text parsing language - first off you have to find a regex engine for it.

Like, for instance, the built-in java.util.regex package?

Re:Ruby not Java (1)

mcrbids (148650) | more than 10 years ago | (#6870629)

That leaves you with choosing one of the scripting languages: Ruby, Perl or Python.

Why is it that when the term "scripting language" is brought up, PHP is so universally forgotten?

It's excellent at text parsing, (which is its native purpose) widely supported, and incredibly flexible.

Re:Ruby not Java (0)

MrBlint (607257) | more than 10 years ago | (#6870685)

I've written many parsers in java and never once found a need for a regex library. The one time I wrote a parser in perl using regular expresions was a nightmare (What do you mean I can't parse recursive structures). The key to writing a nice clean parser in java is to employ the Interpreter design pattern [korea.ac.kr]

Good subject, bad example (2, Interesting)

msuzio (3104) | more than 10 years ago | (#6870385)

The linked article on devx.com really makes me not want to use code generation :-). Let's pick out some fun quotes:

"Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."

----

" For example, when a lot of code needs to be written to perform relatively simple tasks, engineers can smell bad design. The EJB platform requires the construction of a bunch of classes and interfaces for each database table. Some consider this a design smell."

----

Wow. So I have boring meetings and a really bad platform to look forward to. Yowza, bring it on!

OK, I'm partially joking here. But I think it's worth considering... when we're glad that we have a tool to alleviate the hassles of using a technology (like EJBs), maybe the technology and platform needs to be reconsidered? Shouldn't the platform perhaps do more to "hide" the complexity from us?

I'm struggling with this in a similar form right now with SOAP. I'm deploying a set of SOAP services in Java using Apache AXIS [apache.org] implementation. It does a lot of the 'heavy lifting' for you, but I'm still struggling with the particulars of how to deploy a service, serialize/deserialize my classes, ensure this API works well across a variety of clients (I'm testing with Perl, PHP, and Java), etc.

It can be a bit daunting. But... simple things *are* simple, and the level of code generation available is just about right. I don't *have* to generate a bunch of "helper" classes to put a SOAP service out there, the Axis implementation hides most of those details. I *can* generate additonal classes, and customize my WSDD and WSDL files to handle more complex situations, though. So, it's not perfect, but maybe it hits the mark a little closer.

Anyway, code generation can be great. I've done it before with things like interface creation (take an interface description and go to either HTML or Swing), and it can be very handy. But I wouldn't want to implement a system that is unusuable as a platform without those tools. Real programmers use vi ;-).

not impressed. (2, Insightful)

Pinball Wizard (161942) | more than 10 years ago | (#6870402)

As engineers we build time-saving applications for others but never think to apply the power of computers to our own problems.

Huh? Software engineers use more software than anyone else. We have tools for our tools. I found the above statement bordering on the ludicrous, and almost stopped reading at this point.

Code that is copied and pasted to multiple places is difficult to maintain properly across all of the copies. Active code generation does not suffer from the same maintainability issues as copy-and-paste coding. When you need fix something, you apply the bug fix to the templates used to generate the code, which then propagates the fix to all of the code maintained by the generator. This design ensures that no code that needs fixing is left scattered around and forgotten.

That's why we use functions and classes. Then, when you change your function, the changes are magically propagated to all the places in your code where that function was called! Copy and paste programming has been frowned upon pretty much since the days when the goto was declared bad programming practice.

It really sounds like this book is just putting on a fancy name for an incomplete set of good programming practices. Really, what is covered here that Design Patterns doesn't cover in a much more thorough and professional way?

Code generators are just compilers... (3, Interesting)

Dr. Zowie (109983) | more than 10 years ago | (#6870403)

The obvious case is a generator that writes "C" code -- after all, "C" was intended as just a metalanguage like Gnu's RTL, but for the earlier BCMP compiler. It's arguable that generated C code is more true to the spirit of the language than is hand-coded C code.

I became a code-generation convert about two years ago when I first encountered Perl Data Language -- what made PDL development feasible was a code generator by Lukka, Glazebrook, and Soeller: their generator ("PP") writes all the loops and conditionals that do vectorized processing of large arrays.

Of course, PP has its limitations -- the age old complaint of engineers is that they will eventually outgrow any code generation framework -- but it's simple enough to augment the generation language or, in extreme cases, to sidestep the parts of the functionality that you're not using.

Re:Code generators are just compilers... (1)

Dr. Zowie (109983) | more than 10 years ago | (#6870735)

Jeez, shouldn't post before coffee. That's "BCPL" of course, not "BCMP"...

Been doing this for YEARS (1)

renehollan (138013) | more than 10 years ago | (#6870406)

Heck, I've been doing this for years, generally in the area of test automation.

There are usually two cases:

1. The need to automate the generation of some type of code or script for a large number of test cases, where the scripts would otherwise be generated manually.

2. The need to generate tests to excercise implementations from what can best be described as a machine readable description of interfaces and exchanged data types.

The second case is rather interesting in that all the information in most client/server IDLs is usually sufficient to describe the objects that can be passed (via the building of the stubs for their marshalling/demarshalling), as well as the interfaces themselves.

Of course, compilers for more traditional languages generally the structural information for object classes directly, and could output this for the benefit of automaticallly generating test clients for a particular interface, but getting that data out of the compiler's symbol table is often like pulling teeth.

Code generation a necessity (3, Insightful)

russotto (537200) | more than 10 years ago | (#6870408)

I work on a large Java project where we use entity EJBs. Code generation isn't an _option_ here, it's a necessity. We have hundreds of tables (over 500) and each of them has an EJB. Writing out the infrastructure for each and every one by hand would be a huge and boring waste of time. I think the necessity for code generation actually points to a problem with design of EJB itself, but that we're pretty much stuck with.

Re:Code generation a necessity (1)

Make (95577) | more than 10 years ago | (#6870486)

Interesting point, a design flaw in EJB itself... I thought of this many times. I never use code generators, OTOH I don't work on such projects, and I would hate to do it.

Code generation is a kind of compression. i.e., the generated source code has a very high redundancy level. This is what I criticize about code generators: when the generated code is redundant, why not create a better language which expresses my ideas in a non-redundant way?

The "real" code for your EJB's is stored in GUI forms, not in the code itself... but I want to write my code in a plain text editor. I think I would accept some kind of "super-high level" language which compiles into the redundant Java source code.. the "more geek way" to do it?

Re:Code generation a necessity (1)

bmj (230572) | more than 10 years ago | (#6870592)

You know, this is a good point. I've done my fair share of EJB programming, and now I'm using the Torque [apache.org] framework as an object management layer. Torque will generate your business objects from an XML database schema. It _is_ nice, but it's basically the same class with different getter/setter methods. Perhaps there is a better way to do it.

Re:Code generation a necessity (4, Insightful)

BigGerman (541312) | more than 10 years ago | (#6870617)

there is a _huge_ design problem with EJB.
To me it manifests itself in the ass-first design:
if I work with a framework, the typical scenario for OOP would be: framework provides interface, I implement it with my classes so they can play in the framework.
With EJBs, it is another way around: you define an interface and the container/framework creates classes and implements your interface for you!
Code generaton became so popular with J2EE for this very reason: there is _always_ a step where you need to produce a lot of redundant EJB artifacts so you might as well automate it.

If you're going to use big words... (2, Informative)

brooks_talley (86840) | more than 10 years ago | (#6870437)

...it's really important to use them properly. "No pretense of ambivalence," indeed! What, are reference materials supposed to be ambivalent?

From http://www.hyperdictionary.com/dictionary/ambivale nt :

1. [adj] uncertain or unable to decide about what course to follow; "was ambivalent about having children"
2. [adj] characterized by a mixture of opposite feelings or attitudes; "she felt ambivalent about his proposal"; "an ambivalent position on rent control"

Is that really what anyone would expect from a reference material? I think the poster wanted "...no pretense of objectivity."

Not that I care that much, of course.

Cheers
-b

Swings and roundabouts (4, Insightful)

Rogerborg (306625) | more than 10 years ago | (#6870457)

I worked at a telco where we generated C code on the fly from high level Structured Definition Language [etsi.org] for the main call control processing.

It was a great idea... in theory. In theory, it was impossible for the implementation to get out of sync with the detailed design (the SDL). In theory, there's no difference between theory and practice, but in practice there is. Some of the features that we had to add simply couldn't be modelled in SDL, plus there were performance issues, and it produced ugly source.

It was used for fifteen years (yeah, pre-ANSI), but it eventually collapsed under the weight of all of the hacks that were required to work around the limitations. We eventually had to admit that the behaviour of the complete source (generated plus all the stuff around it) was now so different from that defined by the SDL that it was no longer worth putting up with the limitations of the SDL.

In the end, we just took a snapshot of the generated code and set developers free to actually fix it rather than hack around it. At that point, there were only a few people left who even knew SDL, so there were very few tears shed. The rest of us cheered, and the product got significantly cleaner as we refactored the bejeesus out of all the generated C and removed the hacks.

I'd recommend giving code generation a try, but don't be ruled by it. Once the product is mature, if the code generation is limiting you, then don't be afraid to drop it and fix the lower level generated code.

Re:Swings and roundabouts (1)

azlondon (542792) | more than 10 years ago | (#6870631)

We did a similar thing - Used code generation to tweak the data model, and quickly prototype alternate ideas. Once we were happy with it, we cut it loose and worked on the code directly. If we had directly coded it by hand (which would have involved a lot of monkey-work), we would have to stick with the original design, flaws and all.

code generation v. decent languages (1)

po8 (187055) | more than 10 years ago | (#6870518)

Most of the examples of code generation I've seen around are basically kludges around insufficiently powerful high-level programming languages. Datatypes and representations should be able to be generic in the programming language; this enables directly coding at the desired level of abstraction. Check out ML or Haskell for one cut on these ideas.

That said, I've been doing CG for a long time :-). The M4 macro preprocessor is a fine tool for this task. See e.g. my student's M4 CG for XCB [pdx.edu] : a classic example, as we were stuck with C as the implementation language (indeed that was the whole point).

um. (1)

pb (1020) | more than 10 years ago | (#6870527)


Ruby is certainly a language that is inspiring a lot of admiration these days (in fact, it's hard to get Dave Thomas to stop talking about it :-), but with the majority of the code-generation examples being for Java-related technologies, I wonder why Java was not selected instead.

Try writing it in Java, and I'll wager that you'll find out why. It'd probably be quicker to write a code generator to write it for you. Use the right tool for the job.

My website uses code generation (1)

PD (9577) | more than 10 years ago | (#6870529)

My website at http://www.pdrap.org [pdrap.org] uses code generation. All my pages are static html, and are generated by a Python script that I wrote from a source+template. The source directory is organized the same way that the site is organized.

When I want to add a new page or section, I just make a new directory and drop a document into it. When I want to add photos to my photo album, I just make a directory and drop my photos into it. The script takes care of everything else. It reads the source directory, generates new pages into a cache area. Then I use the unison program (rsync protocol) to put all the changed pages into the web server directory.

The end result is that I can add whatever I want to my website without having to write html, or run any CGI, javascript, or anything like that on the webserver.

Re:My website uses code generation (0, Troll)

Laplace (143876) | more than 10 years ago | (#6870614)

Too bad your site looks like ass. And not the good, firm, round female kind.

Why?! (1)

jon3k (691256) | more than 10 years ago | (#6870532)

Why would you ever create redundant code? With or without code generation? Isn't that why we have modular programming languages? Functions and sub routines? Templates and header files? Am I missing something here? This is the first I've heard of it, maybe I should do a little more reading?

Integrating Java and Ruby (1)

Colonel Panic (15235) | more than 10 years ago | (#6870551)

I also found myself wondering about the lack of discussion of how to integrate these Ruby tools into a typical Java build process. Many developers I know use ant to bring automation and consistency to their builds, yet the book doesn't mention this. (JRuby anyone?)

Just a heads up about integrating Java and Ruby:
There is a tool called rjni (Ruby JNI), from the README:

"What is rjni?

rjni exposes the Java Native Interface to Ruby. This allows the programmer to instantiate Java objects, manipulate them, define Java classes, etc... from Ruby. " [and that's the way it should be, use Ruby to drive Java ;-) ]

You could probably use this to drive ANT from Ruby.

You can find rjni at:
http://www.thekode.net/ruby/rjni

It only recently became available (in July) so it wasn't available in time to be included in the Code Generation book.

I thought J2EE was supposed to simplify things (3, Insightful)

KenSeymour (81018) | more than 10 years ago | (#6870552)

A quote from the Sun web site:

J2EE technology and its component based model simplifies enterprise development and deployment.

But now I hear that we need code generation to keep up with all the mundane tasks made necessary by the use of EJBs.
So we build a code generator and we have to maintain that.

This is on top of all the J2EE design patterns you are supposed to do because the world would come to an end if you just accessed a database table using JDBC directly.

Once in a while someone should look at the assertion that it would be harder to maintain a lot of imbedded JDBC code in your application than it would be maintain the 5 or so classes you need for each business object in order to maintain architectural purity.

So what is "Code Generation"? (0)

MegaFur (79453) | more than 10 years ago | (#6870559)

Surprise! It's Yet Another Cross Compiler (but it's not a yacc) :-P

Oh I don't know. Is this progress or not? I can't tell. One of the articles linked to says that code generation is not a symptom of bad design, but I'm reluctant to start using language two to write the code I originally intended to write in language one to be compiled an executed on computer A.

But then, on the other hand, we have yacc/bison and (f)?lex. These programs are used for generating C code for certain pieces of (or sometimes all of) a compiler. In a sense, this is the "code generation" that the book is talking about. This means that the idea proposed by the book is not wholey (bad sp) new and this increases the chance that the "code generation" idea is not indicative of a slippery slope into an evil hell of overcomplex code and languages.

So I ask again: Is this progress? I still can't tell.

Actually, a very interesting topic (4, Informative)

SWPadnos (191329) | more than 10 years ago | (#6870626)

For those who are saying that the term "Code Generator" isn't applicable - it is. Consider a C++ compiler. It may generate asm code, which then gets converted into machine code.

(generic) C++ -> (specific) asm -> executable bits

(obviuosly, the C/C++ compiler doesn't need to generate asm, but it's still code generation if it does)

Code generators just take this a level higher, so the code "life cycle" looks like this:

(generic) Diagram / CG description -> (specific implementation) C++ -> (specific machine) asm -> machine code.

Code generators have a great potential for easing coding and documentation. Just like GCC has many backends to generate code for different processor architectures, the code compilers can have different backends to make source code in different languages (C, C++, Fortran, whatever). Even better, you can run a different translator and get documentation out of the "source" - in HTML, DocBook, XML, or any other format you want.

There are tools to let you make UML diagrams (Google for "Executable UML" for great goodness), and generate real-time C code for an application, a C++ app simulator that runs on a PC, and documentation for the system, all from the same diagram. The tools are expensive (like $15k-$30k), but for large projects, they can be a great savings.

I saw a program called BridgePoint (from Project Technologies [projtech.com] ), which was able to generate embedded, real-time code that was as efficient (more in some areas, less in others, but it averaged out the same) as hand-optimized code done by expert programmers. It all depends on how goo dyour translator is (and this program lets you write your own).

Some books on the subject:
"Executable UML: A Foundation for Model-Driven Architecture", by Stephen J. Mellor and Marc J. Balcer
"Executable UML: The Models are the Code", by Leon Starr
"Real-Time UML: Developing Efficient Objects for Embedded Systems, Second Edition", by Bruce Powel Douglass

true story (2, Interesting)

geekoid (135745) | more than 10 years ago | (#6870635)

I wrote a 'software generator'. It worked so well, they laid of 3 coders, and yes I was one of them.

"Hey, this guy figure out a way to increase productivty to a point we can let three programmers go!"
"Well then, lets be sure one of them is the guy who figures out how to save us money!"

What about expressing concepts at a higher level? (1)

sisukapalli1 (471175) | more than 10 years ago | (#6870737)

Could be a little OT...

Generating a lot of repetitive code can be done by the computer, but can't that be taken care of at a layer that the end user need not worry about -- by defining the higher level concepts at the language level?

Here is an example: In Perl, there is a module called Class::ObjectTemplate. It is a template that can be used to define classes. A code can work as follows:

package MyClass;
use Class:ObjectTemplate;
require exporter;
@ISA = ("Class::ObjectTemplate");

attributes("a", "b", "c", "d");

That's it. Now, MyClass has accessor methods, a constructor, and so on...

my $m = MyClass->new();
$m->a("Hello");
my $x = $m->a();

and so on.

The difference between this and the Code Generation utilities is that there is no intermediate code for the programmar to tweak. Everything is right there.

S
Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Create a Slashdot Account

Loading...