News for hackers. Stuff that matters.
Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by dgb23 on Sunday July 30, 2023 @01:36PM (#36933735)
I’ve become a fan of code generation (data driven).

The benefits: you write code faster, automatically uniform and the result is “dumb” and less abstract AKA easy to debug and modify. Tedium/boilerplate is gone, you focus in the overall model.

The costs: you think more up front, you have to see the result first (hand written). It’s easy to see common patterns too early.

With some patience, caution and experience some of the costs can be mitigated.

Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by lovasoa on Sunday July 30, 2023 @01:42PM (#36933843)
I loved the idea of code generation when I first encountered it, but I've since come to hate it.

A large code base that was auto-generated and then subtly modified in some places is hard to refactor, and if you need to change the signature of a function that is used thousands of time across the generated code, you are in for a long ride.

Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by dgb23 on Sunday July 30, 2023 @01:46PM (#36933889)
Yes it’s easy to go overboard with it. I don’t have a clear recipe for which parts it makes sense, except that it emerges from hand written code.
Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by deterministic on Monday July 31, 2023 @12:58AM (#36938959)
There is an art to writing good code generators. Bad code generators are really really bad. Good code generators are absolutely awesome! I have saved thousands of hours using my own code generators. But I have also seen very bad code generators in the wild that I wouldn’t recommend using.
Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by semicolon_storm on Sunday July 30, 2023 @01:58PM (#36934048)
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.
Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by epolanski on Sunday July 30, 2023 @04:30PM (#36935630)
We 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.

Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by t1mmen on Sunday July 30, 2023 @09:57PM (#36938035)
Can 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.

Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by epolanski on Monday July 31, 2023 @09:58AM (#36942554)
Yes, 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

Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by t1mmen on Monday July 31, 2023 @07:25PM (#36950269)
Thank you, I appreciate you sharing some code :)
Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by deterministic on Monday July 31, 2023 @12:53AM (#36938942)
It 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.
Re:Repeating Yourself Thrice Doesn’t Turn You into a 3x Deve... by deterministic on Monday July 31, 2023 @12:52AM (#36938925)
Same here. A code generator I wrote at work has saved an enormous amount of work hours for everybody. It is super popular.

I routinely generate 80% of the code needed to implement a typical business application.