News for hackers. Stuff that matters.
Re:Building a High Performance Data Integration Framework in Go by Xeoncross on Monday November 28, 2022 @03:48PM (#33779392)
Code generation is becoming really important in Go.

Why even use an ORM when https://sqlc.dev/ will generate everything from vanilla SQL?

Why make the frontend team write a Typescript client when https://goa.design on the backend will produce an OpenAPI schema they can just point a https://openapi-generator.tech at?

Why write out GraphQL boilerplate when https://github.com/99designs/gqlgen will take your GQL typedef and generate it all for you based on how you want it to look.

Why write validation rules when you can just define your input struct and let https://github.com/mustafaakin/gongular generate the rest for you?

Honestly, I'm loving this. I want to focus on the entities and business logic - not writing yet another handler/resolver for basic auth + CRUD work.

Re:Building a High Performance Data Integration Framework in Go by lairv on Monday November 28, 2022 @04:27PM (#33779956)
sqlc is great but what I dislike about it is that it forces into using only the supported underlying drivers, for example with postgresql the pgx v5 driver has been out for some times now but sqlc only support v4 (this might have changed recently I haven't checked).

Overall there are many reasons why I would like to generate code slightly differently from what is done in the lib, I wish there was a way to have a highly customizable code generation experience

Re:Building a High Performance Data Integration Framework in Go by jerf on Monday November 28, 2022 @04:03PM (#33779591)
It would be interesting for the annual Go survey to include a question about how much code generation is being used in the wild. My personal impression is that it is not widespread at all, but I phrase it that way on purpose.
Re:Building a High Performance Data Integration Framework in Go by halpmeh on Monday November 28, 2022 @04:27PM (#33779958)
We've been using it for mocks and protocol buffers for many years. I'm sure we're not alone.
Re:Building a High Performance Data Integration Framework in Go by zinclozenge on Monday November 28, 2022 @03:57PM (#33779519)
Gongular looks pretty cool, but it seems like development stopped. Is there any other library that does similar things?

I love learning about new frameworks/libraries in golang for exactly that reason of reducing boilerplate and spending more time on logic.

Re:Building a High Performance Data Integration Framework in Go by stuzenz on Monday November 28, 2022 @05:19PM (#33780677)
Interesting response here in the issues.

The project is still active. It seems that feature requests and issues are not being asked of the project.

https://github.com/mustafaakin/gongular/issues/21

Re:Building a High Performance Data Integration Framework in Go by yevpats on Monday November 28, 2022 @03:55PM (#33779487)
100% ORMs becoming less and less relevant especially in Go with code generation and a bit of copilot help :).

Also, Protobuf is another (not new) but good example of client and server side code generation which passed the time test.

Re:Building a High Performance Data Integration Framework in Go by leetbulb on Monday November 28, 2022 @05:14PM (#33780619)
Check out Ent https://entgo.io/docs/code-gen

Pretty easy to generate GraphQL (most fully featured extension), OpenAPI, Protobuf, etc. from your database schema. Ent also makes it easy to implement your own generators (e.g. OAS, glue logic, etc).

Re:Building a High Performance Data Integration Framework in Go by Xeoncross on Monday November 28, 2022 @08:31PM (#33782509)
The problem with Ent is you are neither 1) writing your SQL structures or 2) writing your Go structures. Instead, you're writing Ent-specific structures.

It's still a good option, just sad we keep inventing more abstraction layers that are unique in each language. That is a benefit of GraphQL typedefs, JSON, and SQL - it's the same in every language.

Re:Building a High Performance Data Integration Framework in Go by ilyt on Monday November 28, 2022 @05:32PM (#33780827)
It's real shame it's kinda bad language for it. Looking at what people did with Rust macros it's shame that Go code generation story is either "just run some random binaries to compile stuff" or "put code instructing the compiler to do stuf in fucking comments"

And I say it without being sarcastic but Go makes me miss C preprocessor and nothing should make anyone miss C preprocessor.

Re:Building a High Performance Data Integration Framework in Go by rad_gruchalski on Monday November 28, 2022 @07:05PM (#33781749)
> put code instructing the compiler to do stuf in fucking comments

Funny considering how Rust does stuff.

Both approaches have pros and cons. One either digs through a shitload of macros, or commits explicit auto generated code.

Re:Building a High Performance Data Integration Framework in Go by ilyt on Tuesday November 29, 2022 @10:37AM (#33788830)
Yeah the annotations in Rust suffer from bit of that but macros don't.

I yearn for ability to make error handling macros...

Re:Building a High Performance Data Integration Framework in Go by teeray on Monday November 28, 2022 @07:18PM (#33781863)
It’s like metaprogramming in Ruby again, except with the idea that it’s somehow more straightforward because you can inspect the generated code. Except nobody will ever inspect auto-generated code because a) it’s usually awful code b) ignoring that code was kind of the whole point.
Re:Building a High Performance Data Integration Framework in Go by philosopher1234 on Tuesday November 29, 2022 @03:21AM (#33784979)
>Looking at what people did with Rust macros it's shame that Go code generation story is either "just run some random binaries to compile stuff" or "put code instructing the compiler to do stuf in fucking comments"

Why is it a shame? Rely on macros and this is what you get:

1. Slow compile times

2. Unsearchable (grep, sourcegraph...) code

3. Magic codebases. Longer learning curve

To me, working in a large organization, those are big downsides.

Re:Building a High Performance Data Integration Framework in Go by ilyt on Tuesday November 29, 2022 @10:38AM (#33788842)
The article is about code generation that is more magic than macros.
Re:Building a High Performance Data Integration Framework in Go by philosopher1234 on Tuesday November 29, 2022 @08:41PM (#33795858)
but you can inspect the generated code, jump to def, search it... how the actual generation works may be magic, but the code is reviewable, searchable, debuggable...

Its clearly better than macros for my use cases

Re:Building a High Performance Data Integration Framework in Go by gmhafiz on Monday November 28, 2022 @07:24PM (#33781920)
Sqlc quickly breaks down when you want to do dynamic select. This is where an orm, or query builder shines
Re:Building a High Performance Data Integration Framework in Go by stereosteve on Monday November 28, 2022 @09:43PM (#33783049)
Agreed. I am experimenting with using go-jet instead and it’s going real good so far.

https://github.com/go-jet/jet

Re:Building a High Performance Data Integration Framework in Go by User23 on Monday November 28, 2022 @09:38PM (#33783017)
It's nice that they exist, but these workarounds are only necessary because Go isn't a very expressive language. I don't really consider having to use a third party tool to generate boilerplate as part of a multi-stage build process to really be a great thing, but I guess it's better than not having those tools if you choose to use Go for some reason.