3 ms·
I'm of the opinion that if you have to generate code, then there's something wrong. It may be that you're using a library or language that's out of your control
by rlpb 17y ago
I'm of the opinion that if you have to generate code, then there's something wrong. It may be that you're using a library or language that's out of your control, in which case fair enough.
The difficulty comes when you suddenly find yourself having to debug generated code and you find that it has become impenetrable and unreadable. The same problem arises when introducing a new programmer to the project as well.
This is why I favour Python and Ruby (edit: and Lisp of course!) type languages. You can meta-program your way out of any code generation requirement. Instead of refactoring a DRY problem by using code generation, you solve it with meta-code. This is what makes these languages truly agile.
- DanielBMarkham 17y agohe difficulty comes when you suddenly find yourself having to debug generated code and you find that it has become impenetrable and unreadable So don't do that. When you find yourself doing that, you know you've gone too far. I think maybe you've misunderestimated me: F# is a functional language. It'd be easy enough to abstract my way into all kinds of scary stuff. Code generation is a form of meta-programming and abstraction. I find it useful in certain circumstances, like when I'd like to have types to inspect that are going to match up perfectly with my persistence framework. Language-level abstraction takes away the touchy-feely inspection I like, and there's no point re-inventing the wheel. Simply kick out a template and don't worry about it. But you're absolutely right that in general, copy-and-pasting and code generation are signs that you are doing bad things. Just not always :)