I think go generate is awesome, specially when combined of other toolkit goodnesses, like build tags, awesome community tools and external build tools.
But it has its drawbacks, and it imposes some workflow restrictions that make it not always a desirable solution.
The main problem being it doesn't "run automatically" when you go get packages, so you have to do this, and that, and that.
What if go had something like go generate that runs automagically in every step of the process? We could use go to "deal with" our go code, and then we could use go to generate go code! Go is fast, it would be fast. Go is awesome, it would be awesome. I think it could even help with generics, since it would be basically free to generate typed code. We could have real ORMs!
I mean, look at AutoValue, isn't that a beautiful solution to some stupid problems? Why can't we have that?
评论:
:
comrade_donkey:[deleted]
thockin:** I would love to provide some citation on this, but I'll have to go and find it.
Just keep in mind that it is for package authors, not clients, if only for the reason that the program it invokes might not be available on the target machine. Also, if the containing package is intended for import by go get, once the file is generated (and tested!) it must be checked into the source code repository to be available to clients.
The hoops that kubernetes has to jump through are incredibly unfortunate, but the truth is that we have to codegen a bunch for performance reasons. The generated code is our #1 cause of merge conflicts and rebases across contributors. Moving to just-in-time codegen is what we want, but we t requires horrible, ridiculous 'makefile' hacks.
Something better would be wonderful.
