in reply to Code Generators as tests.

This is a very interesting subject, and I'm always surprised that Perlfolk don't deal with this more often since Perl has great text manipulation built-in and available world class templating systems.

That said, I strongly disagree with keeping generated code in the source control system. In my experience this winds up getting out of sync with the actual state of the project. Developers should be aware that changes are being made to the generated code, and the best way to make them aware of this is when they need to compile additional files whenever they build the project. Smart code generators will not regenerate a file if it has the same content as one that already exists, which will lessen or eliminate the "having to recompile" everything problem.

I think the other conditions you speak of here indicate a code generation system needing repair. (I hesitate to say "broken" because it clearly functions, but suboptimally.) If people are treating the code generator as a black box then they need to understand the parameters for changing the generated code: how easy is it, what are typical changes, etc.

I'm ambivalent about whether all developers need to know everything about the code generation system. It would be a great situation if they did and prevent the 'guru getting hit by a bus' problem, but most often there's simply not enough time.

As usual: according to my experience, with my two cents, etc.

Chris
M-x auto-bs-mode

Replies are listed 'Best First'.
Re: Re: Code Generators as tests.
by dpuu (Chaplain) on Aug 19, 2002 at 21:12 UTC
    Until fairly recently, I'd have agreed with you. However, I think it is human nature that is broken, not my code generation environments :-). In my experence, once you start programming with meta data, the meta deta evolves to become turing complete. People want to have conditionals (and later, iteration) within the abstraction that they are concentrating on. And "people" includes me!

    Smart generators may be able to avoid regenerating files that don't change; but many versions of "make" are dumb: they see the dependency in the DAG and follow it all the way up: they don't check to see if the output really changed at a given step.

    I am not really suggesting that you put generated code in the source control system: I'm suggesting that you put source code in it. The fact that you used an automated partner to help you write that code is unimportant.

    I am very aware of the the tendency for the checked-in and generated codes to diverge: that's what the tests are for. They fail when the two are different. At that point, there's a choice: either fix the test (i.e. the generator), or throw it away (the generator was just a wizard). --Dave