4 ms·
I work at a company that does a lot of code generation, and it gets uglier the longer you do it. It's much harder to write the code that generates the code you
by semicolon_storm 3y ago
I work at a company that does a lot of code generation, and it gets uglier the longer you do it. It's much harder to write the code that generates the code you want than to just write the damn code in the first place. The abstractions & assumptions made for your code generator will eventually begin to break down, and when that finally happens everything goes from a simple refactoring to way overly complicated update to the generator.
- deterministic 3y agoIt sounds as if the code generators you use are pretty bad. The ones I use at work are fantastic. It has literally saved me (and others) thousands of hours of boring tedious work.
- epolanski 3y agoWe too do lots of code generation, but I have the opposite experience. The articles example would imply in our use case: 1) add one key to the schema (which is database independent), which will generate encoders, decoders, apis (to work with the data structure, not in network-sense) automatically 2) add the key in the views you want to add it (when updating/reading or more complex network apis) 3) specify how the key is retrieved/saved in the use cases (controller-like) 4) use the key in the frontend. It took me longer to write this post from mobile than it would've taken me do the first 3 steps.
- t1mmen 3y agoCan I ask your stack/toolkit? Sounds fantastic! I’m on my first project that resembles your description, and I _really_ like it (so far). Auto-documentation is also a big plus, imo. Our “truth schema” also outputs OpenAPI specs, markdown docs, etc with zero added effort (past writing inline comments). Love it.
- epolanski 3y agoYes, and I wish we had more time to document and clean it up for users outside our company because it's pretty incomprehensible for users outside it. Notice that we use a custom typescript compiler (tsplus), we make use of some quite advanced typescript, and we add codegeneration via eslint on top of it. Took me 3 months here before it started making sense, but then it started clicking. https://github.com/effect-ts-app/boilerplate https://github.com/effect-ts-app/boilerplate
- t1mmen 3y agoThank you, I appreciate you sharing some code :)