5 ms·
I can only think of two use cases for code generation: For performance in super specific situations where you can use it like a jit of sorts to reduce overhead
by ltbarcly3 5y ago
I can only think of two use cases for code generation:
For performance in super specific situations where you can use it like a jit of sorts to reduce overhead.
To intentionally obfuscate code or avoid shipping core logic to clients for fear it will be copied.
Any other use is probably just inexperienced programmers trying to find a way to write higher level code and failing.
- klelatti 5y agoI'm using code generation to go from a super simple finance DSL to a c program which then gets compiled using clang. Could I do it without code generation? Maybe, but I get the flexibility of a dynamic language to do the DSL parsing etc. I see it as a bit like LLVM - an intermediate stage that adds flexibility.
- ltbarcly3 5y agoYou are describing a compiler, not code generation as I am criticizing. When people generate code, the generated code is the code they check in and modify going forward, not just some intermediate step in a language implementation.
- HelloNurse 5y agoThere's a misunderstanding, generated code is only "modified going forward" by very immature organizations. For extra negative credits there is the false idol of "round-trip engineering", like in the old Together Control Center, usually involving UML. Generating from nice models and nice templates (the real source code) verbose and correct "boilerplate" that won't be usually read, let alone modified, is simply a shift to an ad hoc, specialized programming language.
- klelatti 5y agoYou were critical of this tool. I could easily see this tool being used for my use case. It generates human readable c which I can exactly what I want and is not what compilers do. Who says you have to check the generated code in and modify it going forward? You're commenting on your own definition of 'code generator' without properly considering this tool and its use cases.
- ltbarcly3 5y agoSo its just yet another templating language. Congratulations on that I guess? Did you make this? It seems like you and HelloNurse are very upset by anything that suggests this isn't perfect.
- deleted 5y ago[deleted]
- klelatti 5y agoSo you're criticising templating languages now. No point in engaging further. Bye.
- ltbarcly3 5y agoWell, I use templating languages and I think they are quite useful. I've used many in my career, probably 10 or more. Now there is another one, which is good to know I guess.
- deleted 5y ago[deleted]
- HelloNurse 5y agoAre you sure the programming language and libraries you are using allow this "higher level code"? Code generators are a general way to write low redundancy "higher level code" as input models and templates with minimal disruption of technology choices, without the effort, uncertainty and unreasonable cost of looking for "better" languages and libraries.
- ltbarcly3 5y agoYou sound like a consultant who talks about programming but has never done any. The words kindof make sense in the order you are saying them, but I can't find any relationship to reality. Are you some kind of GPT bot?
- HelloNurse 5y agoI suspect your "reality" consists of very small and very homogeneous projects that leave you a fair chance of doing well with simple refactoring and reorganizations, not to mention starting from scratch frequently. But generating code allows you to make changes that cannot be expressed well in your programming language or using your libraries, for example validating the same data in the same way in two different front ends that don't allow refactoring.
- deleted 5y ago[deleted]