6 ms·
Ribosome – A simple generic code generation tool
- mwcampbell 5y agoIs it just a coincidence that I submitted one of Pieter Hintjens's old articles about code generation earlier today? If I'm not mistaken, Martin Sustrik worked with Hintjens.
- mr_vile 5y agoYou're right, they both worked on ZMQ together, however Sustrik disagreed with some of the design decisions and decided to make nanomsg. Hintjens and co have worked on code generation tools since the mid-90's. Read the zproto github page for more information!
- deleted 5y ago[deleted]
- unixhero 5y agoWhen would one use this? In a build toolchain?
- nmridul 5y agoWeb templates ? Thought most template languages like Jinja behaves similar.
- ltbarcly3 5y agoI 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.
- zeptonix 5y agoSeems like they could have made some different design decisions to make the input a lot more readable. Also IMHO code generation should be a last-resort anti-pattern; after all that's what you (the programmer with a brain) are for.
- thecupisblue 5y ago> Also IMHO code generation should be a last-resort anti-pattern; after all that's what you (the programmer with a brain) are for. Code generation should be the "first-resort" pattern. When talking code generation, it enforces you to think about your data model, your flow, patterns, usability, readability. It is perfect to build repetitive boilerplate you can type on your own without thinking, so instead of taking up 10 minutes fighting input/UX bandwith of your hands and tools, you can generate huge chunks of code you would have to write anyways (and possibly make a mistake).
- ltbarcly3 5y agoYou should not have repetitive boilerplate at all, and if your speed of programming is limited by how fast you can type you are writing some really bad code without understanding high level programming at all.
- auxym 5y agoWhat about things like protobufs?
- thecupisblue 5y agoRepetitive boilerplate isn't just "wrapper spaghetti code". Repetitive boilerplate is what builds systems. If I can make a model that has 50 lines and will generate 50 different classes, 50 files and 600 methods where I only need to fill out the expressions, that is writing code. If I am going to say how it's all boilerplate and write it by hand, chances are I will have something nobody else will understand with bugs I cant remember or will have to rewrite the above by hand into a boiler-plate-like way again, which to me, makes no sense to do manually.
- the_gipsy 5y agoWouldn't it be more readable if the "syntax" was the other way round? My instinct tells me that I'd prefer to read the output-code better, and that the generation would just be simple stuff.