Unix Programming - Basics of the Unix Philosophy - Rule of Generation: Avoid hand-hacking; write programs to write
Rule of Generation: Avoid hand-hacking; write programs to write
programs when you can.
Human beings are notoriously bad at sweating the details.
Accordingly, any kind of hand-hacking of programs is a rich source of
delays and errors. The simpler and more abstracted your program
specification can be, the more likely it is that the human designer
will have gotten it right. Generated code (at
every level) is almost always cheaper and more
reliable than hand-hacked.
We all know this is true (it's why we have compilers and
interpreters, after all) but we often don't think about the
implications. High-level-language code that's repetitive and
mind-numbing for humans to write is just as productive a target for a
code generator as machine code. It pays to use code generators when
they can raise the level of abstraction — that is, when the
specification language for the generator is simpler than the generated
code, and the code doesn't have to be hand-hacked afterwards.
In the Unix tradition, code generators are heavily used to
automate error-prone detail work. Parser/lexer generators are the
classic examples; makefile generators and GUI interface builders are
newer ones.